Search documentation of jhn_stdlib

# jhn_p_tree (jhn_stdlib v5.10.3)

View Source

Implements Prefix trees that allows you to find a value associated with the longest prefix of the key used. All keys are lists of terms.

# Summary

## Types

default/0
flag/0
key/0
p_tree/0
value/0

## Functions

add(Key, Value, Tree)

The Value is saved in Tree under the Key, if that key is present the value associated with the key is replaced by Value. add(Key, Value, Tree) is equivalent to add(Key, Value, Tree,nocheck).

add(T, Value, Tree, Flag)

The Value is saved in Tree under the Key, if that key is present the value associated with the key is replaced by Value. If the flag is check an exception is generated and if nocheck the value is replaced.

adds(Pairs, Tree)
adds(Pairs, Tree, _)

For each {Key, Value} pair in Pairs the value is stored under the key in the Tree. If an key already has a value associated with in the Tree the flag determines what happens. If the flag is check an exception is generated if a key has a value associated with it, if the flag is nocheck the values will be replaced.

delete(Key, Tree)

If a value is associated the Key the Tree returned has that association removed. The call delete(Key, Tree) is equivalent to delete(Key, Tree, nocheck).

delete(T, P_node, Flag)

If a value is associated the Key the Tree returned has that association removed. If there is no value associated with the Key in the Tree the flag determines what happens. If the flag is check an exception is generated if no association exists, if the flag is nocheck the unchanged tree is returned.

deletes(Keys, Tree)

A tree that has all the associations for the keys removed. The call deletes(Indces, Tree) is equivalent to deletes(Keys, Tree, nocheck).

deletes(Keys, Tree, _)

A tree that has all the associations for the keys removed. If there is no value associated with any of the Keys in the Tree, the flag determines what happens. If the flag is check an exception is generated if, if the flag is nocheck a tree is returned with the other associations removed.

find(Key, Tree)

Returns the value associated with the longest prefix of the Key in the Tree or undefined if no such association exists. The call find(Key, Tree) is equivalent to find(Key, Tree, undefined).

find(T, P_node, Prev)

Returns the value associated with the longest prefix of the Key in the Tree or Default if no such association exists.

from_list(Plist)

For each {Key, Value} pair in Pairs the value is stored under the key in the Tree.

is_empty(_)

Returns true if the Tree is empty, false otherwise.

is_p_tree(P_node)

Returns true if X is a P-tree, false otherwise.

keys(Tree)

Returns all the keys in ascending order.

member(T, P_node)

Returns true if there is a value associated with Key in the tree, otherwise false.

new()

Creates an empty P-tree.

replace(Key, Value, Tree)

Replaces any existing value associated with Key in the tree, otherwise adds a association for the value with the Key. The call replace(Key, Value, Tree) is equivalent to replace(Key, Value, Tree, nocheck).

replace(Key, Value, Tree, _)

Replaces any existing value associated with Key in the tree, otherwise the flag determines what happens. If the flag is check an exception is generated, otherwise the value is added.

to_list(Tree)

From a P-tree a list of {Key, Value} pairs.

values(Tree)

Returns all the values in ascending order of their keys.

# Types

# default/0

    -type default() :: _.

# flag/0

    -type flag() :: check | nocheck.

# key/0

    -type key() :: [_].

# p_tree/0

    -opaque p_tree()

# value/0

    -type value() :: _.

# Functions

# add(Key, Value, Tree)

    -spec add(key(), value(), p_tree()) -> p_tree().

The Value is saved in Tree under the Key, if that key is present the value associated with the key is replaced by Value. add(Key, Value, Tree) is equivalent to add(Key, Value, Tree,nocheck).

# add(T, Value, Tree, Flag)

    -spec add(key(), value(), p_tree(), flag()) -> p_tree().

The Value is saved in Tree under the Key, if that key is present the value associated with the key is replaced by Value. If the flag is check an exception is generated and if nocheck the value is replaced.

# adds(Pairs, Tree)

    -spec adds([{key(), value()}], p_tree()) -> p_tree().

# adds(Pairs, Tree, _)

    -spec adds([{key(), value()}], p_tree(), flag()) -> p_tree().

For each {Key, Value} pair in Pairs the value is stored under the key in the Tree. If an key already has a value associated with in the Tree the flag determines what happens. If the flag is check an exception is generated if a key has a value associated with it, if the flag is nocheck the values will be replaced.

# delete(Key, Tree)

    -spec delete(key(), p_tree()) -> p_tree().

If a value is associated the Key the Tree returned has that association removed. The call delete(Key, Tree) is equivalent to delete(Key, Tree, nocheck).

# delete(T, P_node, Flag)

    -spec delete(key(), p_tree(), flag()) -> p_tree().

If a value is associated the Key the Tree returned has that association removed. If there is no value associated with the Key in the Tree the flag determines what happens. If the flag is check an exception is generated if no association exists, if the flag is nocheck the unchanged tree is returned.

# deletes(Keys, Tree)

    -spec deletes([key()], p_tree()) -> p_tree().

A tree that has all the associations for the keys removed. The call deletes(Indces, Tree) is equivalent to deletes(Keys, Tree, nocheck).

# deletes(Keys, Tree, _)

    -spec deletes([key()], p_tree(), flag()) -> p_tree().

A tree that has all the associations for the keys removed. If there is no value associated with any of the Keys in the Tree, the flag determines what happens. If the flag is check an exception is generated if, if the flag is nocheck a tree is returned with the other associations removed.

# find(Key, Tree)

    -spec find(key(), p_tree()) -> value() | undefined.

Returns the value associated with the longest prefix of the Key in the Tree or undefined if no such association exists. The call find(Key, Tree) is equivalent to find(Key, Tree, undefined).

# find(T, P_node, Prev)

    -spec find(key(), p_tree(), default()) -> value() | default().

Returns the value associated with the longest prefix of the Key in the Tree or Default if no such association exists.

# from_list(Plist)

    -spec from_list([{key(), value()}]) -> p_tree().

For each {Key, Value} pair in Pairs the value is stored under the key in the Tree.

# is_empty(_)

    -spec is_empty(_) -> boolean().

Returns true if the Tree is empty, false otherwise.

# is_p_tree(P_node)

    -spec is_p_tree(_) -> boolean().

Returns true if X is a P-tree, false otherwise.

# keys(Tree)

    -spec keys(p_tree()) -> [key()].

Returns all the keys in ascending order.

# member(T, P_node)

    -spec member(key(), p_tree()) -> boolean().

Returns true if there is a value associated with Key in the tree, otherwise false.

# new()

    -spec new() -> p_tree().

Creates an empty P-tree.

# replace(Key, Value, Tree)

    -spec replace(key(), value(), p_tree()) -> p_tree().

Replaces any existing value associated with Key in the tree, otherwise adds a association for the value with the Key. The call replace(Key, Value, Tree) is equivalent to replace(Key, Value, Tree, nocheck).

# replace(Key, Value, Tree, _)

    -spec replace(key(), value(), p_tree(), flag()) -> p_tree().

Replaces any existing value associated with Key in the tree, otherwise the flag determines what happens. If the flag is check an exception is generated, otherwise the value is added.

# to_list(Tree)

    -spec to_list(p_tree()) -> [{key(), value()}].

From a P-tree a list of {Key, Value} pairs.

# values(Tree)

    -spec values(p_tree()) -> [key()].

Returns all the values in ascending order of their keys.