Radix.merge
You're seeing just the function
merge
, go back to Radix module for more information.
Specs
Merges two radix trees into one.
Adds all key,value-pairs of tree2
to tree1
, overwriting any existing entries.
Example
iex> tree1 = new([{<<0>>, 0}, {<<1>>, 1}])
iex> tree2 = new([{<<0>>, nil}, {<<2>>, 2}])
iex> merge(tree1, tree2)
...> |> to_list()
[{<<0>>, nil}, {<<1>>, 1}, {<<2>>, 2}]
Specs
Merges two radix trees into one, resolving conflicts through fun
.
Adds all key,value-pairs of tree2
to tree1
, resolving conflicts through
given fun
. Its arguments are the conflicting key/0
and the value/0
found in tree1
and the value/0
found in tree2
.
Example
# keep values of tree1, like merge(tree2, tree1)
iex> tree1 = new([{<<0>>, 0}, {<<1>>, 1}])
iex> tree2 = new([{<<0>>, nil}, {<<2>>, 2}])
iex> merge(tree1, tree2, fn _k, v1, _v2 -> v1 end)
...> |> to_list()
[{<<0>>, 0}, {<<1>>, 1}, {<<2>>, 2}]