abstract datatype: tree(Payload)
empty/0 | Returns a new empty tree. |
is_prefix_tree/1 | Determines whether the given term is a prefix tree. |
from_map/1 | Converts a map of paths to payloads into a prefix tree. |
fold_prefixes_of/4 | Folds over all nodes in the tree which are prefixed by the given Path
building an accumulated value with the given fold function and initial
accumulator. |
find_path/2 | Returns the payload associated with a path in the tree. |
update/3 | Updates a given path in the tree. |
empty() -> tree(term())
Returns a new empty tree.
See also: tree().
is_prefix_tree(Prefix_tree::tree(term())) -> true
is_prefix_tree(Prefix_tree::term()) -> false
Determines whether the given term is a prefix tree.
from_map(Map) -> Tree
Map = #{khepri_path:native_path() => Payload}
Tree = khepri_prefix_tree:tree(Payload)
Payload = term()
Converts a map of paths to payloads into a prefix tree.
fold_prefixes_of(Fun, Acc, Path, Tree) -> Ret
Fun = fun((Payload, Acc) -> Acc1)
Acc = term()
Acc1 = term()
Path = khepri_path:native_path()
Tree = khepri_prefix_tree:tree(Payload)
Payload = term()
Ret = Acc1
Folds over all nodes in the tree which are prefixed by the given Path
building an accumulated value with the given fold function and initial
accumulator.
find_path(Path, Tree) -> Ret
Path = khepri_path:native_path()
Tree = khepri_prefix_tree:tree(Payload)
Payload = term()
Ret = {ok, Payload} | error
returns: {ok, Payload}
where Payload
is associated with the given path
or error
if the path is not associated with a payload in the given tree.
Returns the payload associated with a path in the tree.
update(Fun, Path, Tree) -> Ret
Fun = fun((Payload | '$__NO_PAYLOAD__') -> Payload | '$__NO_PAYLOAD__')
Path = khepri_path:native_path()
Tree = khepri_prefix_tree:tree(Payload)
Payload = term()
Ret = khepri_prefix_tree:tree(Payload)
Updates a given path in the tree.
This function can be used to create, update or delete tree nodes. If the
tree node does not exist for the given path, the update function is passed
?NO_PAYLOAD
. If the update function returns ?NO_PAYLOAD
then the tree
node and all of its ancestors which do not have a payload or children are
removed.
?NO_PAYLOAD
if a tree node exists
but does not have a payload: being passed ?NO_PAYLOAD
is not a reliable
sign that a tree node did not exist prior to an update.
Generated by EDoc