Bloom Filter implementation in Elixir. Bloom filters are probabilistic data structures designed to efficiently tell you whether an element is present in a set.
Add bloom_filter to your list of dependencies in mix.exs
:
def deps do
[{:bloom_filter, "~> 1.0.0"}]
end
iex> f = BloomFilter.new 100, 0.001 # Create a bloom filter with an expected capacity 100 and desired false positive rate < 0.001
iex> f = BloomFilter.add(f, 42)
iex> BloomFilter.has?(f, 42)
true
mix test
A Bloom filter is a space-efficient data structure designed to efficiently tell you whether an element is present in a set. Both insertion and membership operations theoretically cost a constant time O(k)
, where k
is the number of hash functions used in the filter.
The price paid for this efficiency is that a Bloom filter is a probabilistic data structure: it tells us that the element either is definitely NOT in the set or MAYBE in the set.
The filter is essentially a vector of bits (0
or 1
) of some size m
. When we add
a new item
to the filter we map item
to k
number of hash functions, which gives us k
indices. We then set the bits on these indices to 1
.
When we want to check if our filter has?
a particular item
, we feed it to our hash functions again, and check if any?
of the bits are 0
or all?
the bits are 1
. If there are bits that are not set, item
is definitely not in the set. If all the bits are set, item
is probably in the set, since false positives can happen due to collision.
Bloom filters are best suited for applications where the amount of source data would require an impractically large amount of memory if "conventional" error-free hashing techniques were applied.
bloom_filter
uses two hash functions :erlang.phash2
, Fowler–Noll–Vo
, and the Double Hashing technique to generate an arbitrary number of independent hash functions.
bloom_filter
also automatically optimizes the optimal size of the bit vector and the number of hash functions required to attain the user's desired error rate.
You need to have dialyxir installed.
mix dialyzer
- Fork it ( http://github.com/Leventhan/bloom_filter/fork )
- Create your feature branch (
git checkout -b feature/my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin feature/my-new-feature
) - Create new Pull Request (Remember to squash your commits!)
Report any found bugs or errors using the issue tracker.
bloom_filter © 2016+, Yos Riady. Released under the MIT License.
Authored and maintained by Yos Riady with help from contributors (list).