Module p_tree

Implements Prefix trees that allows you to find a value associated with the longest prefix of the key used.

Copyright © (C) 2016-2020, Jan Henry Nystrom <JanHenryNystrom@gmail.com> -------------------------------------------------------------------

Authors: Jan Henry Nystrom (JanHenryNystrom@gmail.com).

Description

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.

Data Types

default()

default() = term()

flag()

flag() = check | nocheck

key()

key() = [term()]

p_tree()

abstract datatype: p_tree()

value()

value() = term()

Function Index

add/3 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/4 The Value is saved in Tree under the Key, if that key is present the value associated with the key is replaced by Value.
adds/2
adds/3 For each {Key, Value} pair in Pairs the value is stored under the key in the Tree.
delete/2 If a value is associated the Key the Tree returned has that association removed.
delete/3 If a value is associated the Key the Tree returned has that association removed.
deletes/2 A tree that has all the associations for the keys removed.
deletes/3 A tree that has all the associations for the keys removed.
find/2 Returns the value associated with the longest prefix of the Key in the Tree or undefined if no such association exists.
find/3 Returns the value associated with the longest prefix of the Key in the Tree or Default if no such association exists.
from_list/1 For each {Key, Value} pair in Pairs the value is stored under the key in the Tree.
is_empty/1 Returns true if the Tree is empty, false otherwise.
is_p_tree/1 Returns true if X is a P-tree, false otherwise.
keys/1 Returns all the keys in ascending order.
member/2 Returns true if there is a value associated with Key in the tree, otherwise false.
new/0 Creates an empty P-tree.
replace/3 Replaces any existing value associated with Key in the tree, otherwise adds a association for the value with the Key.
replace/4 Replaces any existing value associated with Key in the tree, otherwise the flag determines what happens.
to_list/1 From a P-tree a list of {Key, Value} pairs.
values/1 Returns all the values in ascending order of their keys.

Function Details

add/3

add(Key::key(), Value::value(), Tree::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/4

add(T::key(), Value::value(), Tree::p_tree(), Flag::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/2

adds(Pairs::[{key(), value()}], Tree::p_tree()) -> p_tree()

adds/3

adds(Pairs::[{key(), value()}], Tree::p_tree(), X3::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/2

delete(Key::key(), Tree::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/3

delete(T::key(), P_node::p_tree(), Flag::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/2

deletes(Keys::[key()], Tree::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/3

deletes(Keys::[key()], Tree::p_tree(), X3::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/2

find(Key::key(), Tree::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/3

find(T::key(), P_node::p_tree(), Prev::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/1

from_list(Plist::[{key(), value()}]) -> p_tree()

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

is_empty/1

is_empty(X1::term()) -> boolean()

Returns true if the Tree is empty, false otherwise.

is_p_tree/1

is_p_tree(P_node::term()) -> boolean()

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

keys/1

keys(Tree::p_tree()) -> [key()]

Returns all the keys in ascending order.

member/2

member(T::key(), P_node::p_tree()) -> boolean()

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

new/0

new() -> p_tree()

Creates an empty P-tree.

replace/3

replace(Key::key(), Value::value(), Tree::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/4

replace(Key::key(), Value::value(), Tree::p_tree(), X4::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/1

to_list(Tree::p_tree()) -> [{key(), value()}]

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

values/1

values(Tree::p_tree()) -> [key()]

Returns all the values in ascending order of their keys.


Generated by EDoc