View Source ExPoppyServer (ex_poppy v0.2.0)

Documentation for ExPoppyServer.

ExPoppyServer is a genserver holding the reference to a ExPoppy bloom filter in memory. The main purpose of this construct is to avoid reloading a filter when not necessary.

Here is how one would add ExPoppyServer to an application's Supervisor to give access to a filter called host.bloom:

{ExPoppy.ExPoppyServer, name: :poppyserver, path: Path.join([:code.priv_dir(:myapp), "host.bloom"])}

Summary

Functions

Returns the filter's capacity

Returns a specification to start this module under a supervisor.

Checks whether a string may be preesnt in the bloom filter. Returns true or false

Returns the estimate count of elements in the bloom filter

Returns the filter's false positive rate

Inserts a string into the bloomfilter. Returns :ok or {:error, "a message describing the error}

Loads the bloom filter located at path. Returns :ok or {:error, "a message describing the error"}

Saves the bloom filter to a file located at path Returns :ok or {:error, "a message describing the error"}

Starts genserver. Process name can be set in the options.

Returns the filter's version

Functions

Link to this function

capacity(bf_pid)

View Source (since 0.1.0)

Returns the filter's capacity

Examples

iex(8)> ExPoppyServer.capacity(pid)
10000
Link to this function

child_spec(init_arg)

View Source (since 0.1.0)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

contains(bf_pid, string)

View Source (since 0.1.0)

Checks whether a string may be preesnt in the bloom filter. Returns true or false

Examples

iex(5)> ExPoppyServer.contains(pid, "toto")
true
iex(6)> ExPoppyServer.contains(pid, "tata")
false
Link to this function

count_estimate(bf_pid)

View Source (since 0.1.0)

Returns the estimate count of elements in the bloom filter

Examples

iex(2)> ExPoppyServer.insert(pid, "toto")
:ok
iex(3)> ExPoppyServer.insert(pid, "tata")
:ok
iex(4)> ExPoppyServer.count_estimate(pid)
2
Link to this function

fpp(bf_pid)

View Source (since 0.1.0)

Returns the filter's false positive rate

Examples

iex(8)> ExPoppyServer.fpp(pid)
0.001
Link to this function

insert(bf_pid, string)

View Source (since 0.1.0)

Inserts a string into the bloomfilter. Returns :ok or {:error, "a message describing the error}

Examples

iex(4)> ExPoppyServer.insert(pid, "toto")

:ok

Link to this function

load(bf_pid, path)

View Source (since 0.1.0)

Loads the bloom filter located at path. Returns :ok or {:error, "a message describing the error"}

Examples

iex(5)> ExPoppyServer.load(pid, "toto")
:ok
iex(6)> ExPoppyServer.load(pid, "/root/toto")
{:error, "IO error: Permission denied (os error 13)"}
iex(8)> ExPoppyServer.load(pid, "/home/jlouis/tata")
{:error, "IO error: No such file or directory (os error 2)"}
Link to this function

save(bf_pid, path)

View Source (since 0.1.0)

Saves the bloom filter to a file located at path Returns :ok or {:error, "a message describing the error"}

Examples

iex(4)> ExPoppyServer.save(pid, "toto")
:ok
iex(6)> ExPoppyServer.save(pid, "/root/toto")
{:error, "IO error: Permission denied (os error 13)"}
Link to this function

start_link(opts \\ [])

View Source (since 0.1.0)

Starts genserver. Process name can be set in the options.

Examples

iex(1)> {:ok, pid} = ExPoppyServer.start_link([])
{:ok, #PID<0.188.0>}
iex(4)> {:ok, pid2} = ExPoppyServer.start_link([])
** (MatchError) no match of right hand side value: {:error, {:already_started, #PID<0.188.0>}}
Link to this function

version(bf_pid)

View Source (since 0.1.0)

Returns the filter's version

Examples

iex(7)> ExPoppyServer.version(pid)
2