Radix.pop

You're seeing just the function pop, go back to Radix module for more information.
Link to this function

pop(tree, key, opts \\ [])

View Source

Specs

pop(tree(), key(), keyword()) :: {value(), tree()}

Removes the value associated with key and returns the matched key,value-pair and the new tree.

Options include:

  • default: value, returned if key could not be matched (defaults to nil)
  • match: :lpm, specifies a longest prefix match instead of an exact match

If given search key was not matched, the tree is unchanged and the key,value-pair will be the search key and the default value.

Examples

# pop an existing element
iex> new([{<<0>>, 0}, {<<1>>, 1}, {<<2>>, 2}])
...> |> pop(<<1>>)
{
  {<<1>>, 1},
  {0, {6, [{<<0>>, 0}], [{<<2>>, 2}]}, nil}
}

# pop non-existing, using a default
iex> new([{<<0>>, 0}, {<<1>>, 1}, {<<2>>, 2}])
...> |> pop(<<3>>, default: :notfound)
{
  {<<3>>, :notfound},
  {0, {6, {7, [{<<0>>, 0}], [{<<1>>, 1}]}, [{<<2>>, 2}]}, nil}
}

# pop using longest prefix match
iex> t = new([{<<1, 1, 1>>, "1.1.1.0/24"}, {<<1, 1, 1, 1::1>>, "1.1.1.128/25"}])
iex> pop(t, <<1, 1, 1, 255>>, match: :lpm)
{
  {<<1, 1, 1, 1::1>>, "1.1.1.128/25"},
  {0, [{<<1, 1, 1>>, "1.1.1.0/24"}], nil}
}