Iptrie.filter
You're seeing just the function
filter
, go back to Iptrie module for more information.
Specs
Returns a new Iptrie, keeping only the entries for which fun
returns truthy.
The signature for fun
is (key, maxlen, value -> boolean), where the (radix)
key is the original bitstring of the prefix of type maxlen, used to store some
value in that particular radix tree in given trie
.
Radix trees that are empty, are removed from the new Iptrie.
Note that, if need be, Pfx.new(key, maxlen)
reconstructs the original
prefix used to store the value in the trie
.
Example
iex> ipt = new()
...> |> put("acdc:1975::/32", "rock")
...> |> put("acdc:1976::/32", "rock")
...> |> put("abba:1975::/32", "pop")
...> |> put("abba:1976::/32", "pop")
...> |> put("1.1.1.0/24", "v4")
iex>
iex> filter(ipt, fn _bits, maxlen, _value -> maxlen == 32 end)
...> |> to_list()
[{%Pfx{bits: <<1, 1, 1>>, maxlen: 32}, "v4"}]
iex>
iex> filter(ipt, fn _bits, _max, value -> value == "rock" end)
...> |> to_list()
...> |> Enum.map(fn {pfx, value} -> {"#{pfx}", value} end)
[
{"acdc:1975:0:0:0:0:0:0/32", "rock"},
{"acdc:1976:0:0:0:0:0:0/32", "rock"}
]