Verified Commit 91c5870a authored by Camil Staps's avatar Camil Staps 🙂

Fix signedness of shiftr and runblocks implementation in murmurHash2

parent ad7a48a7
Pipeline #43919 passed with stage
in 7 minutes and 10 seconds
......@@ -24,7 +24,7 @@ definition module iTasks.Internal.Generic.Hash
*/
import StdGeneric
from StdInt import instance * Int, IF_INT_64_OR_32, bitxor, >>
from StdInt import instance * Int, IF_INT_64_OR_32, bitxor
from StdList as StdList import qualified foldl
from StdMaybe import :: Maybe
from StdOverloaded import class toInt(..), class toString(..), class *(*), class +(+)
......@@ -79,5 +79,8 @@ murmurHash_combine2 x y :== (x bitxor y) * murmurHash_M
//* Prepares an int for incorporation into a murmurHash
murmurHash_prep x
# x = x * murmurHash_M
# x = x bitxor (x >> murmurHash_R)
# x = x bitxor (x shiftrU murmurHash_R)
:== x
//* Unsigned >>
(shiftrU) infix 7 :: !Int !Int -> Int
......@@ -59,9 +59,9 @@ murmurHash_64 s
(if (restlen==4) (rest bitand 0xffffffff) (rest bitand 0xffffffffff))
(if (restlen==6) (rest bitand 0xffffffffffff) rest))
# h = (h bitxor rest) * M
# h = h bitxor (h >> R)
# h = h bitxor (h shiftrU R)
# h = h * M
# h = h bitxor (h >> R)
# h = h bitxor (h shiftrU R)
= h
where
seed = bitnot M
......@@ -72,8 +72,8 @@ where
| i >= end = h
# k = get_int_from_string i s
# k = k * M
# k = k bitxor (k >> R)
# h = (h bitxor (k * M)) * M
# k = k bitxor (k shiftrU R)
# h = (h * M) bitxor (k * M)
= runblocks (i+8) end h
get_int_from_string :: !Int !String -> Int
......@@ -95,9 +95,9 @@ murmurHash_32 s
(if (restlen==0) 0 (rest bitand 0xff))
(if (restlen==2) (rest bitand 0xffff) rest)
# h = (h bitxor rest) * M
# h = h bitxor (h >> 13)
# h = h bitxor (h shiftrU 13)
# h = h * M
# h = h bitxor (h >> 15)
# h = h bitxor (h shiftrU 15)
= h
where
seed = bitnot M
......@@ -108,8 +108,8 @@ where
| i >= end = h
# k = get_int_from_string i s
# k = k * M
# k = k bitxor (k >> R)
# h = (h * M) bitxor k
# k = k bitxor (k shiftrU R)
# h = (h * M) bitxor (k * M)
= runblocks (i+4) end h
get_int_from_string :: !Int !String -> Int
......@@ -119,3 +119,8 @@ where
addI
load_i 8
}
(shiftrU) infix 7 :: !Int !Int -> Int
(shiftrU) _ _ = code inline {
shiftrU
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment