Iptrie.update
You're seeing just the function
update
, go back to Iptrie module for more information.
Specs
Lookup prefix
and update the matched entry, only if found.
Uses longest prefix match, so search prefix
is usually matched by some less
specific prefix. If matched, fun
is called on its value. If
prefix
had no longest prefix match, the trie
is returned unchanged.
Example
iex> ipt = new()
...> |> put("1.1.1.0/24", 0)
...> |> update("1.1.1.0", fn x -> x + 1 end)
...> |> update("1.1.1.1", fn x -> x + 1 end)
...> |> update("2.2.2.2", fn x -> x + 1 end)
iex> get(ipt, "1.1.1.0/24")
{"1.1.1.0/24", 2}
iex> lookup(ipt, "2.2.2.2")
nil
Specs
Lookup prefix
and, if found, update its value or insert the default.
Uses longest prefix match, so search prefix
is usually matched by some less
specific prefix. If matched, fun
is called on the entry's value. If
prefix
had no longest prefix match, the default is inserted and fun
is
not called.
Example
iex> ipt = new()
...> |> update("1.1.1.0/24", 0, fn x -> x + 1 end)
...> |> update("1.1.1.0", 0, fn x -> x + 1 end)
...> |> update("1.1.1.1", 0, fn x -> x + 1 end)
...> |> update("2.2.2.2", 0, fn x -> x + 1 end)
iex> lookup(ipt, "1.1.1.2")
{"1.1.1.0/24", 2}
iex>
iex> # probably not what you wanted:
iex>
iex> lookup(ipt, "2.2.2.2")
{"2.2.2.2", 0}