View Source jhn_r_tree (jhn_stdlib v5.0.6)

Implements range trees, where the tree is organized with non-overlapping ranges.

Summary

Functions

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

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

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

If a value is associated the Range the Tree returned has that association removed. If there is no value associated with the Range 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 ranges removed. The call deletes(Ranges, Tree) is equivalent to deletes(Ranges, Tree, nocheck).

A tree that has all the associations for the rangess removed. If there is no value associated with any of the Ranges 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 any range that includes 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 any range that includes the key in the Tree or Default if no such association exists.

For each {Range, 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 R-tree, false otherwise.

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

Creates an empty R-tree.

Returns all the ranges in ascending order.

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

Replaces any existing value associated with Range 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 R-tree a list of {Range, Value} pairs.

Returns all the values in ascending order of their ranges.

Types

-type default() :: _.
-type flag() :: check | nocheck.
-type key() :: [_].
-opaque r_tree()
-type range() :: {value(), value()}.
-type value() :: _.

Functions

-spec add(range(), value(), r_tree()) -> r_tree().

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

Link to this function

add(R, Value, Tree, Flag)

View Source
-spec add(range(), value(), r_tree(), flag()) -> r_tree().

The Value is saved in Tree under the Range, 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([range()], r_tree()) -> r_tree().
-spec adds([{range(), value()}], r_tree(), flag()) -> r_tree().

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

-spec delete(range(), r_tree()) -> r_tree().

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

-spec delete(range(), r_tree(), flag()) -> r_tree().

If a value is associated the Range the Tree returned has that association removed. If there is no value associated with the Range 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([range()], r_tree()) -> r_tree().

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

Link to this function

deletes(Ranges, Tree, _)

View Source
-spec deletes([range()], r_tree(), flag()) -> r_tree().

A tree that has all the associations for the rangess removed. If there is no value associated with any of the Ranges 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(), r_tree()) -> value() | undefined.

Returns the value associated with any range that includes the key in the Tree or undefined if no such association exists. The call find(Key, Tree) is equivalent to find(Key, Tree, undefined).

Link to this function

find(I, R_node, Default)

View Source
-spec find(key(), r_tree(), default()) -> value() | default().

Returns the value associated with any range that includes the key in the Tree or Default if no such association exists.

-spec from_list([{range(), value()}]) -> r_tree().

For each {Range, 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_r_tree(_) -> boolean().

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

-spec member(range(), r_tree()) -> boolean().

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

-spec new() -> r_tree().

Creates an empty R-tree.

-spec ranges(r_tree()) -> [range()].

Returns all the ranges in ascending order.

Link to this function

replace(Range, Value, Tree)

View Source
-spec replace(range(), value(), r_tree()) -> r_tree().

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

Link to this function

replace(Range, Value, Tree, _)

View Source
-spec replace(range(), value(), r_tree(), flag()) -> r_tree().

Replaces any existing value associated with Range 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(r_tree()) -> [{range(), value()}].

From a R-tree a list of {Range, Value} pairs.

-spec values(r_tree()) -> [value()].

Returns all the values in ascending order of their ranges.