Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Data.BloomFilter.Classic.Internal
Description
Synopsis
- data MBloom s a
- new :: BloomSize -> ST s (MBloom s a)
- maxSizeBits :: Int
- data Bloom a
- bloomInvariant :: Bloom a -> Bool
- size :: Bloom a -> BloomSize
- data Hashes a
- hashes :: Hashable a => a -> Hashes a
- insertHashes :: MBloom s a -> Hashes a -> ST s ()
- elemHashes :: Bloom a -> Hashes a -> Bool
- readHashes :: forall s a. MBloom s a -> Hashes a -> ST s Bool
- freeze :: MBloom s a -> ST s (Bloom a)
- unsafeFreeze :: MBloom s a -> ST s (Bloom a)
- thaw :: Bloom a -> ST s (MBloom s a)
- formatVersion :: Int
- serialise :: Bloom a -> (BloomSize, ByteArray, Int, Int)
- deserialise :: PrimMonad m => MBloom (PrimState m) a -> (MutableByteArray (PrimState m) -> Int -> Int -> m ()) -> m ()
Mutable Bloom filters
A mutable Bloom filter, for use within the ST
monad.
Instances
new :: BloomSize -> ST s (MBloom s a) Source #
Create a new mutable Bloom filter.
The filter size is capped at maxSizeBits
.
maxSizeBits :: Int Source #
The maximum filter size is $2^48$ bits. Tell us if you need bigger bloom filters.
Immutable Bloom filters
An immutable Bloom filter.
bloomInvariant :: Bloom a -> Bool Source #
Hash-based operations
A pair of hashes used for a double hashing scheme.
See evalHashes
.
Instances
Prim (Hashes a) Source # | |
Defined in Data.BloomFilter.Classic.Internal Methods sizeOfType# :: Proxy (Hashes a) -> Int# Source # sizeOf# :: Hashes a -> Int# Source # alignmentOfType# :: Proxy (Hashes a) -> Int# Source # alignment# :: Hashes a -> Int# Source # indexByteArray# :: ByteArray# -> Int# -> Hashes a Source # readByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Hashes a #) Source # writeByteArray# :: MutableByteArray# s -> Int# -> Hashes a -> State# s -> State# s Source # setByteArray# :: MutableByteArray# s -> Int# -> Int# -> Hashes a -> State# s -> State# s Source # indexOffAddr# :: Addr# -> Int# -> Hashes a Source # readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Hashes a #) Source # writeOffAddr# :: Addr# -> Int# -> Hashes a -> State# s -> State# s Source # setOffAddr# :: Addr# -> Int# -> Int# -> Hashes a -> State# s -> State# s Source # |
hashes :: Hashable a => a -> Hashes a Source #
Create Hashes
structure.
It's simply hashes the value twice using seed 0 and 1.
elemHashes :: Bloom a -> Hashes a -> Bool Source #
Query an immutable Bloom filter for membership using already constructed
Hashes
value.
Conversion
freeze :: MBloom s a -> ST s (Bloom a) Source #
Create an immutable Bloom filter from a mutable one. The mutable filter may be modified afterwards.
unsafeFreeze :: MBloom s a -> ST s (Bloom a) Source #
Create an immutable Bloom filter from a mutable one without copying. The
mutable filter must not be modified afterwards. For a safer creation
interface, use freeze
or create
.
thaw :: Bloom a -> ST s (MBloom s a) Source #
Copy an immutable Bloom filter to create a mutable one. There is no non-copying equivalent.
(De)Serialisation
formatVersion :: Int Source #
The version of the format used by serialise
and deserialise
. The
format number will change when there is an incompatible change in the
library, such that deserialising and using the filter will not work.
This can include more than just changes to the serialised format, for
example changes to hash functions or how the hash is mapped to bits.
Note that the format produced does not include this version. Version checking is the responsibility of the user of the library.
The library guarantes that the format version value for the classic (Data.BloomFilter.Classic) and blocked (Data.BloomFilter.Blocked) implementation will not overlap with each other or any previous value used by either implementation. So switching between the two implementations will always be detectable and unambigious.
History:
- Version 0: original
- Version 1: changed range reduction (of hash to bit index) from remainder to method based on multiplication.
serialise :: Bloom a -> (BloomSize, ByteArray, Int, Int) Source #
Serialise the bloom filter to a BloomSize
(which is needed to
deserialise) and a ByteArray
along with the offset and length containing
the filter's bit data.
See also formatVersion
for compatibility advice.
deserialise :: PrimMonad m => MBloom (PrimState m) a -> (MutableByteArray (PrimState m) -> Int -> Int -> m ()) -> m () Source #
Overwrite the filter's bit array. Use new
to create a filter of the
expected size and then use this function to fill in the bit data.
The callback is expected to write (exactly) the given number of bytes into the given byte array buffer.
See also formatVersion
for compatibility advice.