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{}

option()

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

options()

options() = [option()]

Function Index

add/2Equivalent to add(Filter, Data, infinity).
add/3Adds data to the filter.
capacity/1Returns the maximum capacity of the filter.
contains/2Checks if data is in the filter.
delete/2Equivalent to delete(Filter, Data, infinity).
delete/3Deletes data from the filter.
export/1Returns all buckets in the filter as a binary.
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 the filter.

Function Details

add/2

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

Equivalent to add(Filter, Data, infinity).

add/3

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

Adds data to the 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.

capacity/1

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

Returns the maximum capacity of the filter.

contains/2

contains(Filter::cuckoo_filter(), Data::term()) -> boolean()

Checks if data is in the filter.

delete/2

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

Equivalent to delete(Filter, Data, infinity).

delete/3

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

Deletes data from the 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.

export/1

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

Returns all buckets in the filter as a binary.

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

import/2

import(Filter::cuckoo_filter(), 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()) -> non_neg_integer()

Returns number of items in the filter.


Generated by EDoc