From 5565d0bbfb1fbe29258b90dd8bf10c69078cba10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Kr=C3=BCger?= Date: Thu, 4 Nov 2021 20:52:49 +0000 Subject: [PATCH] Allow construction of hashes using their underlying representation --- Data/Digest/Murmur32.hs | 6 +++++- Data/Digest/Murmur64.hs | 6 +++++- changelog.md | 5 +++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Data/Digest/Murmur32.hs b/Data/Digest/Murmur32.hs index 8ea3cd7..239c221 100644 --- a/Data/Digest/Murmur32.hs +++ b/Data/Digest/Murmur32.hs @@ -13,7 +13,7 @@ MurmurHash2 algorithm. See for details on MurmurHash2. -} module Data.Digest.Murmur32 - ( Hash32, asWord32, + ( Hash32, asWord32, asHash32, Hashable32(..), hash32AddWord32, hash32AddInt, hash32, hash32WithSeed ) @@ -39,6 +39,10 @@ instance Show Hash32 where asWord32 :: Hash32 -> Word32 asWord32 (Hash32 w) = w +-- | Coerce a 32 bit word into a hash. This does not hash the input. +asHash32 :: Word32 -> Hash32 +asHash32 = Hash32 + class Hashable32 a where hash32Add :: a -> Hash32 -> Hash32 diff --git a/Data/Digest/Murmur64.hs b/Data/Digest/Murmur64.hs index 6fcb6d4..6128373 100644 --- a/Data/Digest/Murmur64.hs +++ b/Data/Digest/Murmur64.hs @@ -13,7 +13,7 @@ MurmurHash2 algorithm. See for details on MurmurHash2. -} module Data.Digest.Murmur64 - ( Hash64, asWord64, + ( Hash64, asWord64, asHash64, Hashable64(..), hash64AddWord64, hash64AddInt, hash64, hash64WithSeed, combine, ) @@ -39,6 +39,10 @@ instance Show Hash64 where asWord64 :: Hash64 -> Word64 asWord64 (Hash64 w) = w +-- | Coerce a 64 bit word into a hash. This does not hash the input. +asHash64 :: Word64 -> Hash64 +asHash64 = Hash64 + class Hashable64 a where hash64Add :: a -> Hash64 -> Hash64 diff --git a/changelog.md b/changelog.md index 1092f61..6926c06 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,8 @@ +### Unreleased + + - Introduce `asHash64` and `asHash32` which allow construction of `Hash64` + and `Hash32` respectively from their underlying word representation. + ### 0.1.0.10 - Replace use of deprecated `bitSize` by `finiteBitSize`