Skip to content

Commit

Permalink
Use correct prime in combine
Browse files Browse the repository at this point in the history
  • Loading branch information
phadej committed Sep 30, 2021
1 parent e7dec18 commit aa5734a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion CHANGES.md
Expand Up @@ -3,7 +3,11 @@ See also https://pvp.haskell.org/faq
## Version 1.3.4.0
* `Text` and `ByteString` hashes include length.
This fixes a variant of https://github.com/haskell-unordered-containers/hashable/issues/74
for texts and bytestrings
for texts and bytestrings.
https://github.com/haskell-unordered-containers/hashable/pull/223
* Use correct prime in `combine`.
This should improve the hash quality of compound structures on 64bit systems.
https://github.com/haskell-unordered-containers/hashable/pull/224

## Version 1.3.3.0

Expand Down
2 changes: 1 addition & 1 deletion hashable.cabal
@@ -1,6 +1,6 @@
cabal-version: 1.12
name: hashable
version: 1.3.3.0
version: 1.3.4.0
synopsis: A class for types that can be converted to a hash value
description:
This package defines a class, 'Hashable', for types that
Expand Down
4 changes: 4 additions & 0 deletions src/Data/Hashable/Class.hs
Expand Up @@ -868,7 +868,11 @@ foreign import ccall unsafe "hashable_fnv_hash_offset" c_hashByteArray
-- | Combine two given hash values. 'combine' has zero as a left
-- identity.
combine :: Int -> Int -> Int
#if WORD_SIZE_IN_BITS == 64
combine h1 h2 = (h1 * 1099511628211) `xor` h2
#else
combine h1 h2 = (h1 * 16777619) `xor` h2
#endif

instance Hashable Unique where
hash = hashUnique
Expand Down
2 changes: 1 addition & 1 deletion tests/Regress.hs
Expand Up @@ -48,7 +48,7 @@ regressions = [] ++
hs @=? nub hs
#if WORD_SIZE_IN_BITS == 64
, testCase "64 bit Text" $ do
hash ("hello world" :: Text) @=? 1541679664618040100
hash ("hello world" :: Text) @=? -3875242662334356092
#endif
, F.testGroup "concatenation"
[ testCase "String" $ do
Expand Down

0 comments on commit aa5734a

Please sign in to comment.