Skip to content

Commit

Permalink
Switch hashByteArrayWithSalt to SipHash.
Browse files Browse the repository at this point in the history
  • Loading branch information
bos committed Oct 9, 2012
1 parent 6fc98c4 commit 9fa4ca4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Data/Hashable.hs
Expand Up @@ -471,12 +471,12 @@ hashByteArrayWithSalt
-> Int -- ^ length, in bytes
-> Int -- ^ salt
-> Int -- ^ hash value
hashByteArrayWithSalt ba !off !len !h0 =
fromIntegral $ c_hashByteArray ba (fromIntegral off) (fromIntegral len)
(fromIntegral h0)
hashByteArrayWithSalt ba !off !len !h =
fromIntegral $
c_siphash24_offset k0 (fromSalt h) ba (fromIntegral off) (fromIntegral len)

foreign import ccall unsafe "hashable_fnv_hash_offset" c_hashByteArray
:: ByteArray# -> CLong -> CLong -> CLong -> CLong
foreign import ccall unsafe "hashable_siphash24_offset" c_siphash24_offset
:: Word64 -> Word64 -> ByteArray# -> CSize -> CSize -> Word64
#endif

-- | Combine two given hash values. 'combine' has zero as a left
Expand Down
9 changes: 9 additions & 0 deletions cbits/siphash.c
Expand Up @@ -83,3 +83,12 @@ u64 hashable_siphash24(u64 k0, u64 k1, const u8 *str, size_t len)
{
return _siphash(2, 4, k0, k1, str, len);
}

/* Used for ByteArray#s. We can't treat them like pointers in
native Haskell, but we can in unsafe FFI calls.
*/
u64 hashable_siphash24_offset(u64 k0, u64 k1,
const u8 *str, size_t off, size_t len)
{
return _siphash(2, 4, k0, k1, str + off, len);
}

0 comments on commit 9fa4ca4

Please sign in to comment.