Radix.search

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

search(tree, key, type \\ :more)

View Source

Specs

search(tree(), key(), atom()) :: [{key(), value()}]

Returns all key-value-pair(s) based on given search key and match type.

  • :more finds all key,value-pairs where search key is a prefix of key in tree
  • :less finds all key,value-pairs where key in tree is a prefix of the search key.

The search type defaults to :more finding all key,value-pairs whose key matches the search key. Includes search key in the results if present in the radix tree.

Examples

iex> elements = [
...>  {<<1, 1>>, 16},
...>  {<<1, 1, 0>>, 24},
...>  {<<1, 1, 0, 0>>, 32},
...>  {<<1, 1, 1, 1>>, 32}
...> ]
iex> t = new(elements)
iex> search(t, <<1, 1, 0>>)
[{<<1, 1, 0, 0>>, 32}, {<<1, 1, 0>>, 24}]
#
iex> search(t, <<1, 1, 1>>)
[{<<1, 1, 1, 1>>, 32}]
#
iex> search(t, <<2>>)
[]

iex> t = new()
...>   |> put(<<1, 1>>, 16)
...>   |> put(<<1, 1, 0>>, 24)
...>   |> put(<<1, 1, 0, 0>>, 32)
...>   |> put(<<1, 1, 1, 1>>, 32)
iex> search(t, <<1, 1, 1, 1>>, :less)
[{<<1, 1, 1, 1>>, 32}, {<<1, 1>>, 16}]
#
iex> search(t, <<1, 1, 0>>, :less)
[{<<1, 1, 0>>, 24}, {<<1, 1>>, 16}]
#
iex> search(t, <<2, 2>>, :less)
[]