-
Notifications
You must be signed in to change notification settings - Fork 9
Split bloomfilter-blocked into its own package
#770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4bb71e4
Rename `bloomfilter` sub-library to `bloomfilter-blocked`
jorisdral db97e35
Make `bloomfilter-blocked` its own package
jorisdral 453cac6
`bloomfilter-blocked`: update cabal file
jorisdral 6641ff1
`bloomfilter-blocked`: move some docs
jorisdral 69db9f8
`bloomfilter-blocked`: updated documentation
jorisdral File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,6 +89,79 @@ import Data.BloomFilter.Hash | |
|
|
||
| import Prelude hiding (elem, notElem, read) | ||
|
|
||
| -- $overview | ||
| -- | ||
| -- Each of the functions for creating Bloom filters accepts a 'BloomSize'. The | ||
| -- size determines the number of bits that should be used for the filter. Note | ||
| -- that a filter is fixed in size; it cannot be resized after creation. | ||
| -- | ||
| -- The size can be specified by asking for a target false positive rate (FPR) | ||
| -- or a number of bits per element, and the number of elements in the filter. | ||
| -- For example: | ||
| -- | ||
| -- * @'sizeForFPR' 1e-3 10_000@ for a Bloom filter sized for 10,000 elements | ||
| -- with a false positive rate of 1 in 1000 | ||
| -- | ||
| -- * @'sizeForBits' 10 10_000@ for a Bloom filter sized for 10,000 elements | ||
| -- with 10 bits per element | ||
| -- | ||
| -- Depending on the application it may be more important to target a fixed | ||
| -- amount of memory to use, or target a specific FPR. | ||
| -- | ||
| -- As a very rough guide for filter sizes, here are a range of FPRs and bits | ||
| -- per element: | ||
| -- | ||
| -- * FPR of 1e-1 requires approximately 4.8 bits per element | ||
| -- * FPR of 1e-2 requires approximately 9.6 bits per element | ||
| -- * FPR of 1e-3 requires approximately 14.4 bits per element | ||
| -- * FPR of 1e-4 requires approximately 19.2 bits per element | ||
| -- * FPR of 1e-5 requires approximately 24.0 bits per element | ||
|
|
||
|
|
||
| -- $example | ||
| -- | ||
| -- This example reads a dictionary file containing one word per line, | ||
| -- constructs a Bloom filter with a 1% false positive rate, and | ||
| -- spellchecks its standard input. Like the Unix @spell@ command, it | ||
| -- prints each word that it does not recognize. | ||
| -- | ||
| -- @ | ||
| -- import Data.Maybe (mapMaybe) | ||
| -- import qualified Data.BloomFilter as B | ||
| -- | ||
| -- main = do | ||
| -- filt \<- B.fromList (B.policyForFPR 0.01) . words \<$> readFile "\/usr\/share\/dict\/words" | ||
| -- let check word | B.elem word filt = Nothing | ||
| -- | otherwise = Just word | ||
| -- interact (unlines . mapMaybe check . lines) | ||
| -- @ | ||
|
|
||
|
|
||
| -- $differences | ||
| -- | ||
| -- This package is an entirely rewritten fork of | ||
| -- [bloomfilter](https://hackage.haskell.org/package/bloomfilter) package. | ||
| -- | ||
| -- The main differences are | ||
| -- | ||
| -- * This packages support bloomfilters of arbitrary sizes | ||
| -- (not limited to powers of two). Also sizes over 2^32 are supported. | ||
| -- | ||
| -- * The 'Bloom' and 'MBloom' types are parametrised over a 'Hashable' type | ||
| -- class, instead of having a @a -> ['Hash']@ typed field. | ||
| -- This separation allows clean de\/serialization of Bloom filters in this | ||
| -- package, as the hashing scheme is static. | ||
|
||
| -- | ||
| -- * [@XXH3@ hash](https://xxhash.com/) is used instead of Jenkins' | ||
| -- @lookup3@. | ||
|
||
| -- | ||
| -- * Support for both classic and \"blocked\" Bloom filters. Blocked-structured | ||
| -- Bloom filters arrange all the bits for each insert or lookup into a single | ||
| -- cache line, which greatly reduces the number of slow uncached memory reads. | ||
| -- The trade-off for this performance optimisation is a slightly worse | ||
| -- trade-off between bits per element and the FPR. In practice for typical | ||
| -- FPRs of 1-e3 -- 1e-4, this requires a couple extra bits per element. | ||
|
|
||
| -- | Create an immutable Bloom filter, using the given setup function | ||
| -- which executes in the 'ST' monad. | ||
| -- | ||
|
|
@@ -205,75 +278,3 @@ deserialise bloomsalt bloomsize fill = do | |
| mbloom <- stToPrim $ new bloomsalt bloomsize | ||
| Internal.deserialise mbloom fill | ||
| stToPrim $ unsafeFreeze mbloom | ||
|
|
||
| -- $overview | ||
| -- | ||
| -- Each of the functions for creating Bloom filters accepts a 'BloomSize'. The | ||
| -- size determines the number of bits that should be used for the filter. Note | ||
| -- that a filter is fixed in size; it cannot be resized after creation. | ||
| -- | ||
| -- The size can be specified by asking for a target false positive rate (FPR) | ||
| -- or a number of bits per element, and the number of elements in the filter. | ||
| -- For example: | ||
| -- | ||
| -- * @'sizeForFPR' 1e-3 10_000@ for a Bloom filter sized for 10,000 elements | ||
| -- with a false positive rate of 1 in 1000 | ||
| -- | ||
| -- * @'sizeForBits' 10 10_000@ for a Bloom filter sized for 10,000 elements | ||
| -- with 10 bits per element | ||
| -- | ||
| -- Depending on the application it may be more important to target a fixed | ||
| -- amount of memory to use, or target a specific FPR. | ||
| -- | ||
| -- As a very rough guide for filter sizes, here are a range of FPRs and bits | ||
| -- per element: | ||
| -- | ||
| -- * FPR of 1e-1 requires approximately 4.8 bits per element | ||
| -- * FPR of 1e-2 requires approximately 9.6 bits per element | ||
| -- * FPR of 1e-3 requires approximately 14.4 bits per element | ||
| -- * FPR of 1e-4 requires approximately 19.2 bits per element | ||
| -- * FPR of 1e-5 requires approximately 24.0 bits per element | ||
| -- | ||
|
|
||
| -- $example | ||
| -- | ||
| -- This example reads a dictionary file containing one word per line, | ||
| -- constructs a Bloom filter with a 1% false positive rate, and | ||
| -- spellchecks its standard input. Like the Unix @spell@ command, it | ||
| -- prints each word that it does not recognize. | ||
| -- | ||
| -- @ | ||
| -- import Data.Maybe (mapMaybe) | ||
| -- import qualified Data.BloomFilter as B | ||
| -- | ||
| -- main = do | ||
| -- filt \<- B.fromList (B.policyForFPR 0.01) . words \<$> readFile "\/usr\/share\/dict\/words" | ||
| -- let check word | B.elem word filt = Nothing | ||
| -- | otherwise = Just word | ||
| -- interact (unlines . mapMaybe check . lines) | ||
| -- @ | ||
|
|
||
| -- $differences | ||
| -- | ||
| -- This package is an entirely rewritten fork of | ||
| -- [bloomfilter](https://hackage.haskell.org/package/bloomfilter) package. | ||
| -- | ||
| -- The main differences are | ||
| -- | ||
| -- * This packages support bloomfilters of arbitrary sizes | ||
| -- (not limited to powers of two). Also sizes over 2^32 are supported. | ||
| -- | ||
| -- * The 'Bloom' and 'MBloom' types are parametrised over a 'Hashable' type | ||
| -- class, instead of having a @a -> ['Hash']@ typed field. | ||
| -- This separation allows clean de\/serialization of Bloom filters in this | ||
| -- package, as the hashing scheme is static. | ||
| -- | ||
| -- * [@XXH3@ hash](https://xxhash.com/) is used instead of Jenkins' | ||
| -- @lookup3@. | ||
| -- | ||
| -- * Support for both classic and \"blocked\" Bloom filters. Blocked-structured | ||
| -- Bloom filters arrange all the bits for each insert or lookup into a single | ||
| -- cache line, which greatly reduces the number of slow uncached memory reads. | ||
| -- The trade-off for this performance optimisation is a slightly worse | ||
| -- trade-off between bits per element and the FPR. In practice for typical | ||
| -- FPRs of 1-e3 -- 1e-4, this requires a couple extra bits per element. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Up to a maximum of 2^41 bits (256 Gbytes).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or up to a maximum of 2^48 for classic.