Skip to content

Commit 99d1dbb

Browse files
committed
Fix hashing on 32-bit systems (use mmhash32 instead of mmhash128)
1 parent f016f81 commit 99d1dbb

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ authors = ["ScottPJones <[email protected]>"]
44
keywords = ["Strings"]
55
license = "MIT"
66
uuid = "e79e7a6a-7bb1-5a4d-9d64-da657b06f53a"
7-
version = "1.0.1"
7+
version = "1.0.2"
88

99
[deps]
1010
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

src/hash.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ end
3333
_memhash(siz, ptr, seed) =
3434
ccall(Base.memhash, UInt, (Ptr{UInt8}, Csize_t, UInt32), ptr, siz, seed % UInt32)
3535

36-
# Optimized code for hashing empty string
37-
_hash(seed) = last(mmhash128_a(seed%UInt32)) + seed
38-
# Optimized for hashing a UTF-8 compatible aligned string
39-
_hash(str, seed) = last(mmhash128(str, seed%UInt32)) + seed
40-
# For hashing generic abstract strings as if UTF-8 encoded
4136
@static if sizeof(Int) == 8
37+
# Optimized code for hashing empty string
38+
_hash(seed) = last(mmhash128_a(seed%UInt32)) + seed
39+
# Optimized for hashing a UTF-8 compatible aligned string
40+
_hash(str, seed) = last(mmhash128(str, seed%UInt32)) + seed
41+
# For hashing generic abstract strings as if UTF-8 encoded
4242
_hash_abs(str, seed) = last(mmhash128_c(str, seed%UInt32)) + seed
4343
else
44-
function _hash_abs(str, seed)
45-
s = string(str)
46-
@preserve s last(mmhash128_a(sizeof(s), pointer(s), seed%UInt32)) + seed
47-
end
44+
_hash(seed) = MurmurHash3.fmix(seed%UInt32) + seed
45+
# Optimized for hashing a UTF-8 compatible aligned string
46+
_hash(s, seed) = @preserve s mmhash32(sizeof(s), pointer(s), seed%UInt32) + seed
47+
_hash_abs(s, seed) = _hash(string(s), seed)
4848
end
4949

5050
hash(str::Union{S,SubString{S}}, seed::UInt) where {S<:Str} =

0 commit comments

Comments
 (0)