Copyright | (c) Chris Coffey 2018 |
---|---|
License | MIT |
Maintainer | chris@foldl.io |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
This is the internal API and implemntation of CuckooFilter
. It is subject to
change at any time and should not be used. Instead, use the exports from CuckooFilter
.
Synopsis
- newtype Size = Size Natural
- makeSize :: Natural -> Maybe Size
- data Filter a = F {}
- empty :: Size -> Filter a
- newtype FingerPrint = FP Word8
- emptyFP :: FingerPrint
- makeFingerprint :: Hashable a => a -> FingerPrint
- newtype Bucket = B Word32
- emptyBucket :: Bucket
- class Index a where
- newtype IndexA = IA Word32
- newtype IndexB = IB Word32
- replaceInBucket :: FingerPrint -> (FingerPrint -> Bucket -> (Bool, Bool, Bool, Bool)) -> Bucket -> (FingerPrint, Bucket)
- insertBucket :: FingerPrint -> Bucket -> Maybe Bucket
- primaryIndex :: Hashable a => a -> Natural -> IndexA
- secondaryIndex :: FingerPrint -> Natural -> IndexA -> IndexB
- kickedSecondaryIndex :: FingerPrint -> Natural -> IndexB -> IndexB
- getCell :: Bucket -> Natural -> FingerPrint
- setCell :: Bucket -> Natural -> FingerPrint -> Bucket
Constructing a Cuckoo Filter
A non-zero natural number. Generally this is a power of two, although there's no hard requirement for that given the current implementation.
A Cuckoo Filter with a fixed size. The current implementation uses 8 bit fingerprints and 4 element buckets.
Instances
Eq (Filter a) Source # | |
Show (Filter a) Source # | |
Generic (Filter a) Source # | |
ToJSON (Filter a) Source # | |
Defined in Data.CuckooFilter.Internal | |
FromJSON (Filter a) Source # | |
Serialize (Filter a) Source # | |
type Rep (Filter a) Source # | |
Defined in Data.CuckooFilter.Internal type Rep (Filter a) = D1 (MetaData "Filter" "Data.CuckooFilter.Internal" "cuckoo-filter-0.1.0.2-8NKAT7gypEH8pARQbiuTP3" False) (C1 (MetaCons "F" PrefixI True) (S1 (MetaSel (Just "buckets") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (IntMap Bucket)) :*: (S1 (MetaSel (Just "numBuckets") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Natural) :*: S1 (MetaSel (Just "size") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Size)))) |
Creates a new & empty Filter
of size s
Fingerprints
newtype FingerPrint Source #
A FingerPrint is an 8 bit hash of a value
Instances
makeFingerprint :: Hashable a => a -> FingerPrint Source #
hash a % 255. Fingerprints are 8 bits each, and completely opaque to the lookup algorithm.
Working with indices
A Bucket is a statically sized list of four FingerPrints.
emptyBucket :: Bucket Source #
An Index represents the keys into buckets
Instances
Eq IndexA Source # | |
Ord IndexA Source # | |
Show IndexA Source # | |
Generic IndexA Source # | |
Hashable IndexA Source # | |
Defined in Data.CuckooFilter.Internal | |
ToJSON IndexA Source # | |
Defined in Data.CuckooFilter.Internal | |
FromJSON IndexA Source # | |
Serialize IndexA Source # | |
Index IndexA Source # | |
type Rep IndexA Source # | |
Defined in Data.CuckooFilter.Internal |
Instances
Eq IndexB Source # | |
Ord IndexB Source # | |
Show IndexB Source # | |
Generic IndexB Source # | |
Hashable IndexB Source # | |
Defined in Data.CuckooFilter.Internal | |
ToJSON IndexB Source # | |
Defined in Data.CuckooFilter.Internal | |
FromJSON IndexB Source # | |
Serialize IndexB Source # | |
Index IndexB Source # | |
type Rep IndexB Source # | |
Defined in Data.CuckooFilter.Internal |
:: FingerPrint | |
-> (FingerPrint -> Bucket -> (Bool, Bool, Bool, Bool)) | Bucket predicate |
-> Bucket | |
-> (FingerPrint, Bucket) |
insertBucket :: FingerPrint -> Bucket -> Maybe Bucket Source #
secondaryIndex :: FingerPrint -> Natural -> IndexA -> IndexB Source #
(indexA xor
hash fp) % numBuckets
kickedSecondaryIndex :: FingerPrint -> Natural -> IndexB -> IndexB Source #