Radix.lookup_and_update
You're seeing just the function
lookup_and_update
, go back to Radix module for more information.
Specs
Lookup given search key
in tree
and update the value of matched key with
the given function.
If key
is present in map
then the existing value is passed to fun
and
its result is used as the updated value of key
. If key
is not present in
map
, default
is inserted as the value of key
. The default value will
not be passed through the update function.
Examples
iex> t = new()
iex> t = lookup_and_update(t, <<1, 1, 1>>, 1, fn x -> x+1 end)
iex> t
{0, [{<<1, 1, 1>>, 1}], nil}
iex> t = lookup_and_update(t, <<1, 1, 1>>, 1, fn x -> x+1 end)
iex> t
{0, [{<<1, 1, 1>>, 2}], nil}
iex> t = lookup_and_update(t, <<1, 1, 1, 1>>, 1, fn x -> x+1 end)
iex> t
{0, [{<<1, 1, 1>>, 3}], nil}