Copyright © (C) 2021, Matthew Pope
Authors: Matthew Pope.
Interface for the fuse8 filter.
For a full set of examples, see the GitHub README at https://github.com/mpope9/efuse_filter/blob/main/README.md
Example usage:Filter = fuse8:new(["cat", "dog", "mouse"]), true = fuse8:contain(Filter, "cat"), false = fuse8:contain(Filter, "goose").
fuse8() = #fuse8{reference = reference() | undefined, hashing_method = default | none, elements = set:set() | undefined}
| add/2 | Adds elements to filter, and applys the default hashing mechanism if
none wasn't specified in the fuse8:new_empty/1 function. |
| contain/2 | Tests to see if the passed argument is in the filter. |
| contain/3 | Tests to see if the passed argument is in the filter. |
| contain/4 | This function exists for testing if an element exists in a serialized filter with custom hashing. |
| finalize/1 | Initializes filter internally. |
| from_bin/1 | Deserialize the filter from a previous fuse8_to_bin call. |
| from_bin/2 | Deserialize the filter from a previous fuse8_to_bin call. |
| new/1 | Initializes the fuse filter. |
| new/2 | |
| new_empty/0 | Initializes an empty filter. |
| new_empty/1 | Initializes an empty filter. |
| to_bin/1 | Serialize the filter to a binary. |
add(Filter::fuse8:fuse8(), Element::term()) -> fuse8:fuse8() | {error, atom()}
Adds elements to filter, and applys the default hashing mechanism if
none wasn't specified in the fuse8:new_empty/1 function. This function
attempts to catch issues early, before they reach the NIF code. So if
any elements that are passed when custom hashing was specified this
function will return {error, pre_hashed_values_should_be_ints}.
contain(Filter::fuse8:fuse8() | binary(), Key::term()) -> term()
Tests to see if the passed argument is in the filter. The first
argument must be the pre-initialized filter. Returns false if the
argument is not found.
to_bin is allowed
contain(Filter::fuse8:fuse8() | binary(), Key::term(), Default::term()) -> true | term()
Tests to see if the passed argument is in the filter. The first
argument must be the pre-initialized filter. If the value is not found,
the third arguement is returned instead of false.
A filter previously serialized by to_bin is allowed
none then false will be returned.
contain(Filter::binary(), Key::integer(), Default::term(), HashingMethod::none) -> term()
This function exists for testing if an element exists in a
serialized filter with custom hashing.
The first argument should be the pre-initialized and seralized filter.
The second argument is the key that will be tested.
The third arguement is returned instead of false.
The fourth argument should be none.
none then false will be returned.
finalize(Fuse8) -> any()
Initializes filter internally. Equivalent to calling fuse8:new.
Elements are deduplicated at this point, so this function should only fail
if an already intiialized filter is passed to it.
from_bin(X1) -> any()
Deserialize the filter from a previous fuse8_to_bin call. This
will defines the filter to use the default hashing method.
fuse8:fuse8.
from_bin(Binary, X2) -> any()
Deserialize the filter from a previous fuse8_to_bin call. This
will defines the filter to use custom hashing.
fuse8:fuse8.
new(List::[term()]) -> fuse8:fuse8() | {error, atom()}
Initializes the fuse filter
Initializes a fuse8 filter frim the passed values. Each value is hashed
using the erlang:phash2/1 function.
Returns a fuse8 type, which is a filter to be used in contain
If a predefined set of hashes is desired, pass none as the second
argument.
Otherwise, an {error, reason} tuple will be returned.
new(List::[term()], Method::atom()) -> fuse8:fuse8() | {error, atom()}
new_empty() -> fuse8:fuse8()
Initializes an empty filter. This should be filled incrementally. Do not modify the reutrn value of this function.
new_empty(X1::atom()) -> fuse8:fuse8() | {error, atom()}
Initializes an empty filter. This should be filled incrementally.
If a value other than none is passed, then {error, invalid_hash_method}
will be returned. Values passed to fuse8:add/2 need to be pre-hashed as
integers before adding to a filter returned by this function.
Do not modify the return value of this function.
to_bin(Fuse8) -> any()
Serialize the filter to a binary
Returnsbinary().
Generated by EDoc