Skip to content

Commit b9f0d7d

Browse files
committed
fix(bloomfilter): change Salt to a type alias
1 parent cf80d47 commit b9f0d7d

File tree

5 files changed

+11
-15
lines changed

5 files changed

+11
-15
lines changed

bloomfilter/src/Data/BloomFilter/Blocked.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
module Data.BloomFilter.Blocked (
1717
-- * Types
1818
Hash,
19-
Salt (Salt),
19+
Salt,
2020
Hashable,
2121

2222
-- * Immutable Bloom filters

bloomfilter/src/Data/BloomFilter/Blocked/Internal.hs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module Data.BloomFilter.Blocked.Internal (
2020

2121
-- * Hash-based operations
2222
Hashes,
23-
Salt (Salt),
23+
Salt,
2424
Hasher (hashes),
2525
insertHashes,
2626
prefetchInsert,
@@ -54,7 +54,6 @@ import Data.BloomFilter.Blocked.BitArray (BitArray, BitIx (..),
5454
import qualified Data.BloomFilter.Blocked.BitArray as BitArray
5555
import Data.BloomFilter.Classic.Calc
5656
import Data.BloomFilter.Hash
57-
import Data.Word (Word64)
5857

5958
-- | The version of the format used by 'serialise' and 'deserialise'. The
6059
-- format number will change when there is an incompatible change in the
@@ -326,10 +325,6 @@ newtype Hashes a = Hashes Hash
326325
deriving newtype Prim
327326
type role Hashes nominal
328327

329-
-- | The salt value to be used for hashes.
330-
newtype Salt = Salt Word64
331-
deriving stock (Eq, Show)
332-
333328
type Hasher :: (Type -> Type) -> Constraint
334329
class Hasher b where
335330
hashes :: (Hashable a) => b a -> a -> Hashes a
@@ -346,7 +341,7 @@ instance Hasher Bloom where
346341

347342
{-# INLINE hashesWithSalt #-}
348343
hashesWithSalt :: (Hashable a) => Salt -> a -> Hashes a
349-
hashesWithSalt = \ (Salt !salt) !x -> Hashes (hashSalt64 salt x)
344+
hashesWithSalt = \ !salt !x -> Hashes (hashSalt64 salt x)
350345

351346
{-# INLINE blockIxAndBitGen #-}
352347
-- | The scheme for turning 'Hashes' into block and bit indexes is as follows:

bloomfilter/src/Data/BloomFilter/Classic.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module Data.BloomFilter.Classic (
2222

2323
-- * Types
2424
Hash,
25-
Salt (Salt),
25+
Salt,
2626
Hashable,
2727

2828
-- * Immutable Bloom filters

bloomfilter/src/Data/BloomFilter/Classic/Calc.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-- | Various formulas for working with bloomfilters.
22
module Data.BloomFilter.Classic.Calc (
33
NumEntries,
4+
Salt,
45
BloomSize (..),
56
FPR,
67
sizeForFPR,
@@ -13,12 +14,16 @@ module Data.BloomFilter.Classic.Calc (
1314
policyForBits,
1415
) where
1516

17+
import Data.Word (Word64)
1618
import Numeric
1719

1820
type FPR = Double
1921
type BitsPerEntry = Double
2022
type NumEntries = Int
2123

24+
-- | The salt value to be used for hashes.
25+
type Salt = Word64
26+
2227
-- | A policy on intended bloom filter size -- independent of the number of
2328
-- elements.
2429
--

bloomfilter/src/Data/BloomFilter/Classic/Internal.hs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module Data.BloomFilter.Classic.Internal (
2020

2121
-- * Hash-based operations
2222
Hashes,
23-
Salt (Salt),
23+
Salt,
2424
Hasher (hashes),
2525
insertHashes,
2626
elemHashes,
@@ -324,10 +324,6 @@ word64ToWordShim# x# = x#
324324
data Hashes a = Hashes !Hash !Hash
325325
type role Hashes nominal
326326

327-
-- | The salt value to be used for hashes.
328-
newtype Salt = Salt Word64
329-
deriving stock (Eq, Show)
330-
331327
instance Prim (Hashes a) where
332328
sizeOfType# _ = 16#
333329
alignmentOfType# _ = 8#
@@ -457,5 +453,5 @@ instance Hasher Bloom where
457453
--
458454
-- It's simply hashes the value twice using seed 0 and 1.
459455
hashesWithSalt :: Hashable a => Salt -> a -> Hashes a
460-
hashesWithSalt (Salt salt) v = Hashes (hashSalt64 salt v) (hashSalt64 (salt + 1) v)
456+
hashesWithSalt salt v = Hashes (hashSalt64 salt v) (hashSalt64 (salt + 1) v)
461457
{-# INLINE hashesWithSalt #-}

0 commit comments

Comments
 (0)