View Source jhn_pb_tree (jhn_stdlib v5.0.6)

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

Summary

Functions

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).

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.

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.

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).

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.

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

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.

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).

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

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

Returns true if the Tree is empty, false otherwise.

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

Returns all the keys in ascending order.

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

Creates an empty 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).

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.

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

Returns all the values in ascending order of their keys.

Types

-type default() :: _.
-type flag() :: check | nocheck.
-type key() :: binary().
-opaque pb_tree()
-type value() :: _.

Functions

-spec add(key(), value(), pb_tree()) -> pb_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).

Link to this function

add(I, Value, Tree, Flag)

View Source
-spec add(key(), value(), pb_tree(), flag()) -> pb_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.

-spec adds([{key(), value()}], pb_tree()) -> pb_tree().
-spec adds([{key(), value()}], pb_tree(), flag()) -> pb_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.

-spec delete(key(), pb_tree()) -> pb_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).

Link to this function

delete(I, Pb_node, Flag)

View Source
-spec delete(key(), pb_tree(), flag()) -> pb_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.

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

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

-spec deletes([key()], pb_tree(), flag()) -> pb_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.

-spec find(key(), pb_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).

-spec find(key(), pb_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.

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

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

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

Returns true if the Tree is empty, false otherwise.

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

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

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

Returns all the keys in ascending order.

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

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

-spec new() -> pb_tree().

Creates an empty P-tree.

Link to this function

replace(Key, Value, Tree)

View Source
-spec replace(key(), value(), pb_tree()) -> pb_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).

Link to this function

replace(Key, Value, Tree, _)

View Source
-spec replace(key(), value(), pb_tree(), flag()) -> pb_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.

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

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

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

Returns all the values in ascending order of their keys.