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

Link to this type bloomfilter() View Source
bloomfilter() ::
  {:bloom, bitarray :: reference(), bitaddrmask :: integer(),
   number_of_hashes :: 1..8}
Link to this type size_atom() View Source
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

Link to this function estimate_count(arg) View Source
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.

Link to this function false_positive_probability(arg) View Source
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.

Link to this function from_stream(stream) View Source
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?
yesyesno
nomost of the times: nomost of the times: yes
Link to this function has_not?(bloom, term) View Source
has_not?(bloomfilter(), any()) :: boolean()

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)

Link to this function insert(bloom, bin) View Source
insert(bloomfilter(), any()) :: :ok

Inserts an Erlang Term into the Bloom Filter.

Link to this function new(bitaddrlen, expected_elements) View Source
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.

bitaddrlenSizeBitaddrlenSizeBitaddrlenSize
131 KB231 MB
142 KB242 MB
154 KB254 MB
6 8 Byte168 KB268 MB
7 16 Byte1716 KB2716 MB
8 32 Byte1832 KB2832 MB
9 64 Byte1964 KB2964 MB
10128 Byte20128 KB30128 MB
11256 Byte21256 KB31256 MB
12512 Byte22512 KB32512 MB
Link to this function new_by_byte_size(bytes, expected_elements) View Source
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