Iptrie.reduce
You're seeing just the function
reduce
, go back to Iptrie module for more information.
Specs
Invokes fun
on all prefix,value-pairs in all radix trees in trie
.
The function fun
is called with the prefix (a Pfx.t/0
struct), value
and acc
accumulator and should return an updated accumulator. The result
is the last accumulator returned.
Example
iex> ipt = new()
...> |> put("1.1.1.0/24", 1)
...> |> put("2.2.2.0/24", 2)
...> |> put("acdc:1975::/32", 3)
...> |> put("acdc:2021::/32", 4)
iex>
iex> reduce(ipt, 0, fn _pfx, value, acc -> acc + value end)
10
iex>
iex> reduce(ipt, %{}, fn pfx, value, acc -> Map.put(acc, "#{pfx}", value) end)
%{
"1.1.1.0/24" => 1,
"2.2.2.0/24" => 2,
"acdc:1975:0:0:0:0:0:0/32" => 3,
"acdc:2021:0:0:0:0:0:0/32" => 4
}
Specs
Invokes fun
on each prefix,value-pair in the radix tree of given type
in
trie
.
The function fun
is called with the prefix (a Pfx.t/0
struct), value and
acc
accumulator and should return an updated accumulator. The result is
the last accumulator returned.
Example
iex> ipt = new()
...> |> put("1.1.1.0/24", 1)
...> |> put("2.2.2.0/24", 2)
...> |> put("acdc:1975::/32", 3)
...> |> put("acdc:2021::/32", 4)
iex>
iex> reduce(ipt, 32, 0, fn _pfx, value, acc -> acc + value end)
3
iex> reduce(ipt, 48, 0, fn _pfx, value, acc -> acc + value end)
0
iex> reduce(ipt, 128, 0, fn _pfx, value, acc -> acc + value end)
7