Radix.adjacencies

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

Specs

adjacencies(tree()) :: map()

Returns a map where two neighboring key,value-pairs present in tree, are stored under their 'parent' key.

The parent key is 1 bit shorter than that of the two neighboring keys and stores:

  • {key1, val1, key2, val2}, or
  • {key1, val1, key2, val2, val3}

If the parent key exists in the tree as well, its value is included as the fifth-element in the resulting tuple.

Example

iex> tree = new()
...> |> put(<<1, 1, 1, 0::6>>, "1.1.1.0/30")
...> |> put(<<1, 1, 1, 1::6>>, "1.1.1.4/30")
...> |> put(<<1, 1, 1, 2::6>>, "1.1.1.8/30")
...> |> put(<<1, 1, 1, 3::6>>, "1.1.1.12/30")
...> |> put(<<1, 1, 1, 1::5>>, "1.1.1.8/29")
iex> adjacencies(tree)
%{
  <<1, 1, 1, 0::5>> => {
    <<1, 1, 1, 0::6>>, "1.1.1.0/30",
    <<1, 1, 1, 1::6>>, "1.1.1.4/30"
  },
  <<1, 1, 1, 1::5>> => {
    <<1, 1, 1, 2::6>>, "1.1.1.8/30",
    <<1, 1, 1, 3::6>>, "1.1.1.12/30",
    "1.1.1.8/29"}
}