Module cuckoo_filter

High-performance, concurrent, and mutable Cuckoo Filter implemented using atomics for Erlang and Elixir.

Description

High-performance, concurrent, and mutable Cuckoo Filter implemented using atomics for Erlang and Elixir.

Data Types

cuckoo_filter()

cuckoo_filter() = #cuckoo_filter{}

filter_name()

filter_name() = term()

fingerprint()

fingerprint() = pos_integer()

hash()

hash() = non_neg_integer()

index()

index() = non_neg_integer()

option()

option() = {name, filter_name()} | {fingerprint_size, 4 | 8 | 16 | 32 | 64} | {bucket_size, pos_integer()} | {max_evictions, non_neg_integer()} | {hash_function, fun((binary()) -> hash())}

options()

options() = [option()]

Function Index

add/2Equivalent to add(Filter, Element, infinity).
add/3Adds an element to a filter.
add_hash/2Equivalent to add_hash(Filter, Element, infinity).
add_hash/3Adds an element to a filter by its hash.
capacity/1Returns the maximum capacity of a filter.
contains/2Checks if an element is in a filter.
contains_fingerprint/3Checks whether a filter contains a fingerprint at the given index or its alternative index.
contains_hash/2Checks if an element is in a filter by its hash.
delete/2Equivalent to delete(Filter, Element, infinity).
delete/3Deletes an element from a filter.
delete_hash/2Equivalent to delete_hash(Filter, Element, infinity).
delete_hash/3Deletes an element from a filter by its hash.
export/1Exports a filter as a binary.
hash/2Returns the hash value of an element using the hash function of the filter.
import/2Imports filter data from a binary created using export/1.
new/1Equivalent to new(Capacity, []).
new/2Creates a new cuckoo filter with the given capacity and options.
size/1Returns number of items in a filter.
whereis/1Retrieves a cuckoo_filter from persistent_term by its name.

Function Details

add/2

add(Filter::cuckoo_filter() | filter_name(), Element::term()) -> ok | {error, not_enough_space}

Equivalent to add(Filter, Element, infinity).

add/3

add(Filter::cuckoo_filter() | filter_name(), Element::term(), LockTimeout::timeout()) -> ok | {error, not_enough_space | timeout}

add(Filter::cuckoo_filter() | filter_name(), Element::term(), LockTimeout::force) -> ok | {ok, Evicted::{index(), fingerprint()}}

Adds an element to a filter.

Returns ok if the insertion was successful, but could return {error, not_enough_space}, when the filter is nearing its capacity.

When LockTimeout is given, it could return {error, timeout}, if it can not acquire the lock within LockTimeout milliseconds.

If force is given as the 3rd argument, and there is no room for the element to be inserted, another random element is removed, and the removed element is returned as {ok, {Index, Fingerprint}}. In this case, elements are not relocated, and no lock is acquired.

add_hash/2

add_hash(Filter::cuckoo_filter() | filter_name(), Hash::hash()) -> ok | {error, not_enough_space}

Equivalent to add_hash(Filter, Element, infinity).

add_hash/3

add_hash(Filter::cuckoo_filter() | filter_name(), Hash::hash(), LockTimeout::timeout()) -> ok | {error, not_enough_space | timeout}

add_hash(Filter::cuckoo_filter() | filter_name(), Hash::hash(), LockTimeout::force) -> ok | {ok, Evicted::{index(), fingerprint()}}

Adds an element to a filter by its hash.

Same as add/3 except that it accepts the hash of the element instead of the element.

capacity/1

capacity(Cuckoo_filter::cuckoo_filter() | filter_name()) -> pos_integer()

Returns the maximum capacity of a filter.

contains/2

contains(Filter::cuckoo_filter() | filter_name(), Element::term()) -> boolean()

Checks if an element is in a filter.

contains_fingerprint/3

contains_fingerprint(Filter::cuckoo_filter() | filter_name(), Index::index(), Fingerprint::fingerprint()) -> boolean()

Checks whether a filter contains a fingerprint at the given index or its alternative index.

contains_hash/2

contains_hash(Filter::cuckoo_filter() | filter_name(), Hash::hash()) -> boolean()

Checks if an element is in a filter by its hash.

delete/2

delete(Filter::cuckoo_filter() | filter_name(), Element::term()) -> ok | {error, not_found}

Equivalent to delete(Filter, Element, infinity).

delete/3

delete(Filter::cuckoo_filter() | filter_name(), Element::term(), LockTimeout::timeout()) -> ok | {error, not_found | timeout}

Deletes an element from a filter.

Returns ok if the deletion was successful, and returns {error, not_found} if the element could not be found in the filter.

When LockTimeout is given, it could return {error, timeout}, if it can not acquire the lock within LockTimeout milliseconds.

Note: A cuckoo filter can only delete items that are known to be inserted before. Deleting of non inserted items might lead to deletion of another random element.

delete_hash/2

delete_hash(Filter::cuckoo_filter() | filter_name(), Hash::hash()) -> ok | {error, not_found}

Equivalent to delete_hash(Filter, Element, infinity).

delete_hash/3

delete_hash(Filter::cuckoo_filter() | filter_name(), Hash::hash(), LockTimeout::timeout()) -> ok | {error, not_found | timeout}

Deletes an element from a filter by its hash.

Same as delete/3 except that it uses the hash of the element instead of the element.

export/1

export(Filter::cuckoo_filter() | filter_name()) -> binary()

Exports a filter as a binary.

Returned binary can be used to reconstruct the filter again, using import/2 function.

hash/2

hash(Cuckoo_filter::cuckoo_filter() | filter_name(), Element::term()) -> hash()

Returns the hash value of an element using the hash function of the filter.

import/2

import(Filter::cuckoo_filter() | filter_name(), Data::binary()) -> ok | {error, invalid_data_size}

Imports filter data from a binary created using export/1.

Returns ok if the import was successful, but could return {ok, invalid_data_size} if the size of the given binary does not match the size of the filter.

new/1

new(Capacity::pos_integer()) -> cuckoo_filter()

Equivalent to new(Capacity, []).

new/2

new(Capacity::pos_integer(), Opts::options()) -> cuckoo_filter()

Creates a new cuckoo filter with the given capacity and options

Note that the actual capacity might be higher than the given capacity, because internally number of buckets in a cuckoo filter must be a power of 2.

Possible options are:

size/1

size(Cuckoo_filter::cuckoo_filter() | filter_name()) -> non_neg_integer()

Returns number of items in a filter.

whereis/1

whereis(FilterName::filter_name()) -> cuckoo_filter()

Retrieves a cuckoo_filter from persistent_term by its name.


Generated by EDoc