cuckoo_filter() = #cuckoo_filter{}
filter_name() = term()
fingerprint() = pos_integer()
hash() = non_neg_integer()
index() = non_neg_integer()
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() = [option()]
add/2 | Equivalent to add(Filter, Element, infinity). |
add/3 | Adds an element to a filter. |
add_hash/2 | Equivalent to add_hash(Filter, Element, infinity). |
add_hash/3 | Adds an element to a filter by its hash. |
capacity/1 | Returns the maximum capacity of a filter. |
contains/2 | Checks if an element is in a filter. |
contains_fingerprint/3 | Checks whether a filter contains a fingerprint at the given index or its alternative index. |
contains_hash/2 | Checks if an element is in a filter by its hash. |
delete/2 | Equivalent to delete(Filter, Element, infinity). |
delete/3 | Deletes an element from a filter. |
delete_hash/2 | Equivalent to delete_hash(Filter, Element, infinity). |
delete_hash/3 | Deletes an element from a filter by its hash. |
export/1 | Exports a filter as a binary. |
hash/2 | Returns the hash value of an element using the hash function of the filter. |
import/2 | Imports filter data from a binary created using export/1 . |
new/1 | Equivalent to new(Capacity, []). |
new/2 | Creates a new cuckoo filter with the given capacity and options. |
size/1 | Returns number of items in a filter. |
whereis/1 | Retrieves a cuckoo_filter from persistent_term by its name. |
add(Filter::cuckoo_filter() | filter_name(), Element::term()) -> ok | {error, not_enough_space}
Equivalent to add(Filter, Element, infinity).
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.
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(Filter::cuckoo_filter() | filter_name(), Hash::hash()) -> ok | {error, not_enough_space}
Equivalent to add_hash(Filter, Element, infinity).
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 asadd/3
except that it accepts the hash of the element instead
of the element.
capacity(Cuckoo_filter::cuckoo_filter() | filter_name()) -> pos_integer()
Returns the maximum capacity of a filter.
contains(Filter::cuckoo_filter() | filter_name(), Element::term()) -> boolean()
Checks if an element is in a filter.
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(Filter::cuckoo_filter() | filter_name(), Hash::hash()) -> boolean()
Checks if an element is in a filter by its hash.
delete(Filter::cuckoo_filter() | filter_name(), Element::term()) -> ok | {error, not_found}
Equivalent to delete(Filter, Element, infinity).
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.
delete_hash(Filter::cuckoo_filter() | filter_name(), Hash::hash()) -> ok | {error, not_found}
Equivalent to delete_hash(Filter, Element, infinity).
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 asdelete/3
except that it uses the hash of the element instead
of the element.
export(Filter::cuckoo_filter() | filter_name()) -> binary()
Exports a filter as a binary.
Returned binary can be used to reconstruct the filter again, usingimport/2
function.
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(Filter::cuckoo_filter() | filter_name(), Data::binary()) -> ok | {error, invalid_data_size}
Imports filter data from a binary created using export/1
.
new(Capacity::pos_integer()) -> cuckoo_filter()
Equivalent to new(Capacity, []).
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:{name, Name}
If you give it a name, created filter instance will be stored in persistent_term, and later you can access the filter by its name.
{fingerprint_size, FingerprintSize}
FingerprintSize can be one of 4, 8, 16, 32, and 64 bits. Default fingerprint size is 16 bits.
{bucket_size, BucketSize}
BucketSize must be a non negative integer, and the default value is 4. Higher bucket sizes can reduce insert time considerably since it reduces the number of relocations of existing fingerprints in occupied buckets, but it increases the lookup time, and false positive rate.
{max_evictions, MaxEvictions}
MaxEvictions indicates the maximum number of relocation attemps before giving up when inserting a new element.
{hash_function, HashFunction}
You can specify a custom hash function that accepts a binary as argument
and returns hash value as an integer. By default xxh3 hash functions are used,
and you need to manually add xxh3
to the list of your project dependencies.
size(Cuckoo_filter::cuckoo_filter() | filter_name()) -> non_neg_integer()
Returns number of items in a filter.
whereis(FilterName::filter_name()) -> cuckoo_filter()
Retrieves a cuckoo_filter from persistent_term by its name.
Generated by EDoc