Search documentation of jhn_stdlib

# jhn_t_tree (jhn_stdlib v5.10.3)

View Source

Implements T-trees extended with an notion of least upp and greatest lower bounds. For more information on T-Trees see: A Study of Index Structures for Main Memory Database Management Systems. by Tobin J. Lehman and Michael J. Carey, VLDB 1986.

# Summary

## Types

default/0
flag/0
index/0
opt/0
t_tree/0
value/0

## Functions

add(Index, Value, Tree)

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

add(Index, Value, Tree, Flag)

The Value is saved under the Index in the Tree, the Flag determines what should happen if that index already has a value associated with in the Tree. If the flag is check an exception is generated and if nocheck the value is replaced.

adds(Pairs, Tree)

For each {Index, Value} pair in Pairs the value is stored under the index in the Tree. The adds(Pairs, Tree) call is equivalent to adds(Pairs, Tree, nocheck).

adds(Pairs, Tree, _)

For each {Index, Value} pair in Pairs the value is stored under the index in the Tree. If an index 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 index has a value associated with it, if the flag is nocheck the values will be replaced.

delete(Index, Tree)

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

delete(Index, Tree, Flag)

If a value is associated the Index the Tree returned has that association removed. If there is no value associated with the Index 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(Indices, Tree)

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

deletes(Indices, Tree, _)

A tree that has all the associations for the indices removed. If there is no value associated with any of the Indices 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(Index, Tree)

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

find(Index, T_tree, Default)

Returns the value associated with Index in the Tree or Default if no such association exists.

first(Tree)

Returns the value of the smallest index in the Tree or undefined if the tree is empty. The call first(Tree) if equivalent to first(Tree, undefined).

first(T_tree, Default)

Returns the value of the smallest index in the Tree or Default if the tree is empty.

from_list(Pairs)

For each {Index, Value} pair in Pairs the value is stored under the index in the Tree. Equivalent to from_list(Pairs, []).

greatest_lower_bound(Index, Tree)

Returns the value of the largest index that is less or equal to to Index that has a value associated with it, or undefined if no such index exists. The call greatest_lower_bound(Index, Tree) is equivalent to greatest_lower_bound(Index, Tree, undefined).

greatest_lower_bound(Index, T_tree, Default)

Returns the value of the largest index that is less or equal to to Index that has a value associated with it, or Default if no such index exists.

indices(T_tree)

Returns all the indices in ascending order.

is_empty(T_tree)

Returns true if the Tree is empty, false otherwise.

is_t_tree(T_tree)

Returns true if X is a t_tree, false otherwise.

last(Tree)

Returns the value of the largest index in the Tree or undefined if the tree is empty. The call last(Tree) if equivalent to last(Tree, undefined).

last(T_tree, Default)

Returns the value of the largest index in the Tree or Default if the tree is empty.

least_upper_bound(Index, Tree)

Returns the value of the smallest index that is greater or equal to to Index that has a value associated with it, or undefined if no such index exists. The call least_upper_bound(Index, Tree) is equivalent to least_upper_bound(Index, Tree, undefined).

least_upper_bound(Index, T_tree, Default)

Returns the value of the smallest index that is greater or equal to to Index that has a value associated with it, or Default if no such index exists.

member(Index, T_tree)

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

new()

Creates an empty T-tree. The call new() is equivalent to new([]).

new(Opts)

Creates an empty T-tree with min and max internal size according to the options.

replace(Index, Value, Tree)

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

replace(Index, Value, Tree, _)

Replaces any existing value associated with Index 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(T_tree)

From a T-tree a list of {Index, Value} pairs.

values(T_tree)

Returns all the values in ascending order of their indeces.

# Types

# default/0

    -type default() :: _.

# flag/0

    -type flag() :: check | nocheck.

# index/0

    -type index() :: _.

# opt/0

    -type opt() :: {min, pos_integer()} | {max, pos_integer()}.

# t_tree/0

    -opaque t_tree()

# value/0

    -type value() :: _.

# Functions

# add(Index, Value, Tree)

    -spec add(index(), value(), t_tree()) -> t_tree().

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

# add(Index, Value, Tree, Flag)

    -spec add(index(), value(), t_tree(), flag()) -> t_tree().

The Value is saved under the Index in the Tree, the Flag determines what should happen if that index already has a value associated with in the Tree. If the flag is check an exception is generated and if nocheck the value is replaced.

# adds(Pairs, Tree)

    -spec adds([{index(), value()}], t_tree()) -> t_tree().

For each {Index, Value} pair in Pairs the value is stored under the index in the Tree. The adds(Pairs, Tree) call is equivalent to adds(Pairs, Tree, nocheck).

# adds(Pairs, Tree, _)

    -spec adds([{index(), value()}], t_tree(), flag()) -> t_tree().

For each {Index, Value} pair in Pairs the value is stored under the index in the Tree. If an index 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 index has a value associated with it, if the flag is nocheck the values will be replaced.

# delete(Index, Tree)

    -spec delete(index(), t_tree()) -> t_tree().

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

# delete(Index, Tree, Flag)

    -spec delete(index(), t_tree(), flag()) -> t_tree().

If a value is associated the Index the Tree returned has that association removed. If there is no value associated with the Index 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(Indices, Tree)

    -spec deletes([index()], t_tree()) -> t_tree().

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

# deletes(Indices, Tree, _)

    -spec deletes([index()], t_tree(), flag()) -> t_tree().

A tree that has all the associations for the indices removed. If there is no value associated with any of the Indices 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(Index, Tree)

    -spec find(index(), t_tree()) -> value() | undefined.

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

# find(Index, T_tree, Default)

    -spec find(index(), t_tree(), default()) -> value() | default().

Returns the value associated with Index in the Tree or Default if no such association exists.

# first(Tree)

    -spec first(t_tree()) -> value() | undefined.

Returns the value of the smallest index in the Tree or undefined if the tree is empty. The call first(Tree) if equivalent to first(Tree, undefined).

# first(T_tree, Default)

    -spec first(t_tree(), default()) -> value() | default().

Returns the value of the smallest index in the Tree or Default if the tree is empty.

# from_list(Pairs)

    -spec from_list([{index(), value()}]) -> t_tree().

For each {Index, Value} pair in Pairs the value is stored under the index in the Tree. Equivalent to from_list(Pairs, []).

# greatest_lower_bound(Index, Tree)

    -spec greatest_lower_bound(index(), t_tree()) -> value() | undefined.

Returns the value of the largest index that is less or equal to to Index that has a value associated with it, or undefined if no such index exists. The call greatest_lower_bound(Index, Tree) is equivalent to greatest_lower_bound(Index, Tree, undefined).

# greatest_lower_bound(Index, T_tree, Default)

    -spec greatest_lower_bound(index(), t_tree(), default()) -> value() | default().

Returns the value of the largest index that is less or equal to to Index that has a value associated with it, or Default if no such index exists.

# indices(T_tree)

    -spec indices(t_tree()) -> [index()].

Returns all the indices in ascending order.

# is_empty(T_tree)

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

Returns true if the Tree is empty, false otherwise.

# is_t_tree(T_tree)

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

Returns true if X is a t_tree, false otherwise.

# last(Tree)

    -spec last(t_tree()) -> value() | undefined.

Returns the value of the largest index in the Tree or undefined if the tree is empty. The call last(Tree) if equivalent to last(Tree, undefined).

# last(T_tree, Default)

    -spec last(t_tree(), default()) -> value() | default().

Returns the value of the largest index in the Tree or Default if the tree is empty.

# least_upper_bound(Index, Tree)

    -spec least_upper_bound(index(), t_tree()) -> value() | undefined.

Returns the value of the smallest index that is greater or equal to to Index that has a value associated with it, or undefined if no such index exists. The call least_upper_bound(Index, Tree) is equivalent to least_upper_bound(Index, Tree, undefined).

# least_upper_bound(Index, T_tree, Default)

    -spec least_upper_bound(index(), t_tree(), default()) -> value() | default().

Returns the value of the smallest index that is greater or equal to to Index that has a value associated with it, or Default if no such index exists.

# member(Index, T_tree)

    -spec member(index(), t_tree()) -> boolean().

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

# new()

    -spec new() -> t_tree().

Creates an empty T-tree. The call new() is equivalent to new([]).

# new(Opts)

    -spec new([opt()]) -> t_tree().

Creates an empty T-tree with min and max internal size according to the options.

# replace(Index, Value, Tree)

    -spec replace(index(), value(), t_tree()) -> t_tree().

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

# replace(Index, Value, Tree, _)

    -spec replace(index(), value(), t_tree(), flag()) -> t_tree().

Replaces any existing value associated with Index 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(T_tree)

    -spec to_list(t_tree()) -> [{index(), value()}].

From a T-tree a list of {Index, Value} pairs.

# values(T_tree)

    -spec values(t_tree()) -> [index()].

Returns all the values in ascending order of their indeces.