Commit 888a8e78 authored by John van Groningen's avatar John van Groningen

Merge branch '401-fix-murmurHash2' into 'master'

Fix signedness of shiftr and runblocks implementation in murmurHash2

Closes #401

See merge request !440
parents ad7a48a7 60347b42
Pipeline #43921 passed with stage
in 8 minutes and 11 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
......@@ -51,17 +51,11 @@ murmurHash_64 s
# h = runblocks 0 mainlen h
# restlen = len bitand 7
# rest = get_int_from_string mainlen s
# rest = if (restlen<=3)
(if (restlen<=1)
(if (restlen==0) 0 (rest bitand 0xff))
(if (restlen==2) (rest bitand 0xffff) (rest bitand 0xffffff)))
(if (restlen<=5)
(if (restlen==4) (rest bitand 0xffffffff) (rest bitand 0xffffffffff))
(if (restlen==6) (rest bitand 0xffffffffffff) rest))
# rest = rest bitand ((1<<(restlen<<3))-1)
# 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 +66,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
......@@ -91,13 +85,11 @@ murmurHash_32 s
# h = runblocks 0 mainlen h
# restlen = len bitand 3
# rest = get_int_from_string mainlen s
# rest = if (restlen<=1)
(if (restlen==0) 0 (rest bitand 0xff))
(if (restlen==2) (rest bitand 0xffff) rest)
# rest = rest bitand ((1<<(restlen<<3))-1)
# 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 +100,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 +111,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