Module khepri_prefix_tree

Data Types

tree()

abstract datatype: tree(Payload)

Function Index

empty/0Returns a new empty tree.
is_prefix_tree/1Determines whether the given term is a prefix tree.
from_map/1Converts a map of paths to payloads into a prefix tree.
fold_prefixes_of/4Folds 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/2Returns the payload associated with a path in the tree.
update/3Updates a given path in the tree.

Function Details

empty/0

empty() -> tree(term())

Returns a new empty tree.

See also: tree().

is_prefix_tree/1

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/1

from_map(Map) -> Tree

Converts a map of paths to payloads into a prefix tree.

fold_prefixes_of/4

fold_prefixes_of(Fun, Acc, Path, Tree) -> Ret

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

find_path(Path, Tree) -> Ret

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/3

update(Fun, Path, Tree) -> Ret

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.

The update function is also be passed ?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