flower v0.1.4 Flower.Bloom View Source
Flower.Bloom implements a Bloom Filter.
For this Bloom Filter sha256 or sha512 is used as hash function.
Link to this section Summary
Functions
Estimates how many unique elements have been added. This Operation is slow for large Bloom Filters and should then be avoided
Calculates the false positive probability for a given bloom filter.
Return value is between 0.0 and 1.0.
This Operation is slow for large Bloom Filters and should then be avoided
Creates a Bloom Filter from a Stream of binaries. This should be used for deserializing
Checks if an element was inserted in the given Bloom Filter
Checks if an element is not in a given Bloom Filter
Inserts an Erlang Term into the Bloom Filter
Create a new Bloom Filter with size :: size_atom() or 2^bitaddrlen bits
Create a new Bloom Filter with maximum byte size ‘bytes’. The size gets
rounded down to the next size_atom()
Creates a Stream of binaries. This should be used for serializing
Link to this section Types
size_atom() :: :"8 Byte" | :"16 Byte" | :"32 Byte" | :"64 Byte" | :"128 Byte" | :"256 Byte" | :"512 Byte" | :"1 KB" | :"2 KB" | :"4 KB" | :"8 KB" | :"16 KB" | :"32 KB" | :"64 KB" | :"128 KB" | :"256 KB" | :"512 KB" | :"1 MB" | :"2 MB" | :"4 MB" | :"8 MB" | :"16 MB" | :"32 MB" | :"64 MB" | :"128 MB" | :"256 MB" | :"512 MB"
Link to this section Functions
estimate_count(bloomfilter()) :: non_neg_integer()
Estimates how many unique elements have been added. This Operation is slow for large Bloom Filters and should then be avoided.
false_positive_probability(bloomfilter()) :: float()
Calculates the false positive probability for a given bloom filter.
Return value is between 0.0 and 1.0.
This Operation is slow for large Bloom Filters and should then be avoided.
from_stream(Enumerable.t()) :: {:ok, bloomfilter()} | {:error, any()}
Creates a Bloom Filter from a Stream of binaries. This should be used for deserializing.
Example:
file = File.stream!("myfile.bloomfilter", [:read_ahead, :binary], 8096)
Bloom.from_stream(file)
Checks if an element was inserted in the given Bloom Filter.
Returns false if it can be guaranteed that the element was not
inserted. Else true.
You can get the probability of a false positive
using Flower.Bloom.false_positive_probability.
| Was actually inserted? | has? | has_not? |
|---|---|---|
| yes | yes | no |
| no | most of the times: no | most of the times: yes |
Checks if an element is not in a given Bloom Filter.
Returns true if it can be guaranteed that the element was not
inserted. Else false.
This is equal to !Bloom.has?(filter, term)
Inserts an Erlang Term into the Bloom Filter.
new(bitaddrlen :: 6..32, expected_elements :: pos_integer()) :: bloomfilter()
new(bitaddrlen :: size_atom(), expected_elements :: pos_integer()) :: bloomfilter()
Create a new Bloom Filter with size :: size_atom() or 2^bitaddrlen bits.
| bitaddrlen | Size | Bitaddrlen | Size | Bitaddrlen | Size |
|---|---|---|---|---|---|
| 13 | 1 KB | 23 | 1 MB | ||
| 14 | 2 KB | 24 | 2 MB | ||
| 15 | 4 KB | 25 | 4 MB | ||
| 6 | 8 Byte | 16 | 8 KB | 26 | 8 MB |
| 7 | 16 Byte | 17 | 16 KB | 27 | 16 MB |
| 8 | 32 Byte | 18 | 32 KB | 28 | 32 MB |
| 9 | 64 Byte | 19 | 64 KB | 29 | 64 MB |
| 10 | 128 Byte | 20 | 128 KB | 30 | 128 MB |
| 11 | 256 Byte | 21 | 256 KB | 31 | 256 MB |
| 12 | 512 Byte | 22 | 512 KB | 32 | 512 MB |
new_by_byte_size(bytes :: size_atom(), expected_elements :: pos_integer()) :: bloomfilter()
new_by_byte_size(bytes :: pos_integer(), expected_elements :: pos_integer()) :: bloomfilter()
Create a new Bloom Filter with maximum byte size ‘bytes’. The size gets
rounded down to the next size_atom().
Creates a Stream of binaries. This should be used for serializing.
Example:
filter = Bloom.new(...)
file = File.stream!("myfile.bloomfilter", [:delayed_write, :binary], 8096)
Bloom.stream(filter)
|> Stream.into(file)
|> Stream.run