Îõ³h$ £g6      !"#$%&'()*+,-./012345/Copyright © 2019 Lars Kuhtz BSD3Lars Kuhtz  experimentalNone  /ÇÉÙàì 2 cuckooReify type level 6 into 7 value.cuckooAn shorter alias for 8.cuckoofit a b computes how many bs are needed to fit a, i.e. "\left\lceil\frac{a}{b}\right\rceil. For instance,fit 7 33fit 6 32cuckoofit a b computes how many bs are needed to fit a, i.e. "\left\lceil\frac{a}{b}\right\rceil. For instance, intFit 7 33 intFit 6 32cuckoonextPowerOfTwo a computes the smallest power of two that is larger or equal than a.cuckoonextPowerOfTwo a computes the smallest power of two that is larger or equal than a.cuckoo5Computes a 64 bit Fnv1a hash for a value that has an 9 instance.$The first argument is use as a salt.cuckooÁComputes a 64 bit Fnv1a hash for a value that is an instance of :.$The first argument is use as a salt.cuckoo,Computes a Sip hash for a value that has an 9 instance.ÜThe first argument is a salt value that is used to derive the key for the hash computation. cuckoo8Computes a Sip hash for a value that is an instance of :.ÜThe first argument is a salt value that is used to derive the key for the hash computation. cuckoo³An version of a Sip hash that is used internally. In order to avoid dependencies between different hash computations, it shouldn't be used in the implementation of instances of . cuckooWrite a ; value into a < aligned = cuckooGet a ; from a < aligned =.cuckooSaltcuckooValue that is hashescuckooSaltcuckooValue that is hashescuckooSaltcuckooValue that is hashes cuckooSaltcuckooValue that is hashes cuckooindex in terms of <cuckoo; value that is written cuckoo byte arraycuckooindex in terms of <cuckoo*Word64 value that contains the result bits    /Copyright © 2019 Lars Kuhtz BSD3Lars Kuhtz  experimentalNone /9ÉÎØÙàì9 cuckoo&Cuckoo filter that can be used in the > monad.cuckooCuckoo Filter with State token  s :: Type, bucket size b :: Nat,fingerprint size f :: Nat, and content type  a :: Type.The following constraints apply 0 < f \leq 320 < bëThe implementation is not thread safe. For concurrent use the filter must be wrapped in a read-write lock.cuckooñChoosing good hash functions is imperative for a good performance of a cuckoo filter. The hash functions must beindependent and8provide good uniformity on the lower bits of the output.-The default implementations use sip hash for  and  (64 bit) for  and require an instance of 9.instance CuckooFilterHash IntêThe following example uses the hash functions that are provided in this module to define an instance for :%import qualified Data.ByteString as B:{,instance CuckooFilterHash B.ByteString where+ cuckooHash (Salt s) a = fnv1a_bytes s a0 cuckooFingerprint (Salt s) a = sip_bytes s a {-# INLINE cuckooHash #-}$ {-# INLINE cuckooFingerprint #-}:}cuckoo6This function must provide good entropy on the lower 2^b - 1 bits of the result, where b is the number of buckets.cuckooØThis function must provide good entropy on the lower bits of the size of a fingerprint.cuckooSalt for hash computations.cuckooÀCreate a new Cuckoo filter that has at least the given capacity. Enabling the TypeApplicationsß language extension provides a convenient way for passing the type parameters to the function.2:set -XTypeApplications -XDataKinds -XTypeFamilies"newCuckooFilter @4 @10 @Int 0 1000The type parameters are bucket size b :: Nat,fingerprint size f :: Nat, content type  a :: Type, andMonad m :: Type -> Type, The following constraints apply: 0 < f \leq 32,0 < b, and 64 \leq n, where n is the requested size.7The false positive rate depends mostly on the value of f. It is bounded from above by \frac{2b}{2^f}. In most cases 4 is a good choice for b.ðActual performance depends on the choice of good hash functions that provide high uniformity on the lower bits.òThe actual capacity may be much larger than what is requested, because the actual bucket count is a power of two.&f <- newCuckooFilter @4 @10 @Int 0 600capacityInItems f1024sizeInAllocatedBytes f1284cuckoo´Insert an item into the filter and return whether the operation was successful. If insertion fails, the filter is unchanged. An item can be inserted more than once. The return value indicates whether insertion was successful. The operation can fail when the filter doesn't have enough space for the item.•This function is not thread safe. No concurrent writes or reads should occur while this function is executed. If this is needed a lock must be used.ŒThis function is not exception safe. The filter must not be used any more after an asynchronous exception has been thrown during the computation of this function. If this function is used in the presence of asynchronous exceptions it should be apprioriately masked.'f <- newCuckooFilter @4 @10 @Int 0 1000 insert f 0True insert f 0True itemCount f2cuckooÍTest whether an item is in the set that is represented by the Cuckoo filter.¾A negative result means that the item is definitively not in the set. A positive result means that the item is most likely in the set. The rate of false positives is bounded from above by \frac{2b}{2^f} where b( is the number of items per bucket and f& is the size of a fingerprint in bits.'f <- newCuckooFilter @4 @10 @Int 0 1000 insert f 0True member f 0True member f 1FalsecuckooîDelete an items from the filter. An item that was inserted more than once can also be deleted more than once. IMPORTANTö An item must only be deleted if it was successfully added to the filter before (and hasn't been deleted since then).åDeleting an item that isn't in the filter can result in the filter returning false negative results.¦This function is not thread safe. No concurrent writes must occur while this function is executed. If this is needed a lock must be used. Concurrent reads are fine. 'f <- newCuckooFilter @4 @10 @Int 0 1000 insert f 0True insert f 0True itemCount f2 delete f 0True itemCount f1 member f 0True delete f 0True itemCount f0 member f 0FalsecuckooñTotal number of items that the filter can hold. In practice a load factor of ~95% of this number can be reached.cuckooÄThe total number of bytes allocated for storing items in the filter.cuckoo/Number of items currently stored in the filter.Note) that computing this number is expensive \mathcal{O}(n).cuckoo1The current load factor of the filter in percent. 3loadFactor f = 100 * itemCount f / capacityInItems Note) that computing this number is expensive \mathcal{O}(n).cuckooëShow the contents of the filter as a list of buckets with values show in hex. Used for debugging purposes.cuckooêReturns the different hashes that are associated with an item in the filter. Used for debugging purposes.cuckooSalt for the hash functions.cuckooSize. Must be at least 64.   ?      !"#$%&'()*+,-./0123456789:;<:;=>?@>ABCDE>FG>FHIJK:;LÍ#cuckoo-0.2.2-C4opn2bL46b3dVqiJyUfkzData.Cuckoo.Internal Data.CuckooCuckooFilterHashB ByteStringwintfitintFitnextPowerOfTwointNextPowerOfTwofnv1a fnv1a_bytessip sip_bytessip2setgetCuckooFilterIO CuckooFilter cuckooHashcuckooFingerprintSaltnewCuckooFilterinsertmemberdeletecapacityInItemssizeInAllocatedBytes itemCount loadFactor showFilter itemHashes $fShowSlot$fEqSlot $fOrdSlot $fEnumSlot$fIntegralSlot $fRealSlot $fNumSlot $fShowBucket $fEqBucket $fOrdBucket $fEnumBucket$fIntegralBucket $fRealBucket $fNumBucket$fShowFingerprint$fEqFingerprint$fOrdFingerprint $fShowSalt$fEqSalt $fOrdSalt $fEnumSalt$fIntegralSalt $fRealSalt $fNumSaltghc-prim GHC.TypesNatIntbaseGHC.Real fromIntegralForeign.StorableStorable$memory-0.16.0-KzFZHYoqvi3APqTSkh3QMdData.ByteArray.TypesByteArrayAccessGHC.WordWord64Word32'primitive-0.7.1.0-Jxsyd70oUttYiCXCa0HqVData.Primitive.ByteArrayMutableByteArrayIO