|
|
Compare & | key_comp () noexcept |
| | return the comparison criteria
|
| |
| Compare & | get_compare () noexcept |
| |
|
gsl_rng * | gsl_rng_object () noexcept |
| | Get a pointer to gsl random number generator.
|
| |
|
void | set_seed (unsigned long seed) noexcept |
| | Set the random number generator seed.
|
| |
| | Gen_Rand_Tree (unsigned int seed, Compare __cmp=Compare()) noexcept |
| |
| | Gen_Rand_Tree (Compare cmp=Compare()) noexcept |
| |
|
void | swap (Gen_Rand_Tree &tree) noexcept |
| | Swap in constant time all the nodes of this with tree
|
| |
| Node * | insert (Node *p) noexcept |
| |
| Node * | insert_dup (Node *p) noexcept |
| |
| Node * | remove (const Key &key) noexcept |
| |
| Node * | search (const Key &key) const noexcept |
| |
| Node * | search_or_insert (Node *p) noexcept |
| |
|
bool | verify () const |
| | Return true if this is a consistent randomized tree.
|
| |
|
Node *& | getRoot () noexcept |
| | Return the tree's root.
|
| |
| Node * | select (const size_t i) const |
| |
|
size_t | size () const noexcept |
| | Return the number of nodes that have the tree.
|
| |
| std::pair< long, Node * > | position (const Key &key) noexcept |
| |
| std::pair< long, Node * > | find_position (const Key &key) noexcept |
| |
| Node * | remove_pos (const size_t i) noexcept |
| |
| bool | split_key (const Key &key, Gen_Rand_Tree &t1, Gen_Rand_Tree &t2) noexcept |
| |
| void | split_key_dup (const Key &key, Gen_Rand_Tree &t1, Gen_Rand_Tree &t2) noexcept |
| |
| void | split_pos (size_t pos, Gen_Rand_Tree &t1, Gen_Rand_Tree &t2) noexcept |
| |
| void | join (Gen_Rand_Tree &t, Gen_Rand_Tree &dup) noexcept |
| |
| void | join_dup (Gen_Rand_Tree &t) noexcept |
| |
| void | join_exclusive (Gen_Rand_Tree &t) noexcept |
| |
template<template< typename > class NodeType, typename Key, class Compare>
class Aleph::Gen_Rand_Tree< NodeType, Key, Compare >
Randomized binary sarch tree.
This class implements a randomized binary search tree. It is shown that this type of tree always is equivalent to a classic binary search tree built from a random insertion sequence. Consequently, all the operations of this tree are
expected case, independentely of insertion order and of removals are interleaved with insertions.
In addition, these trees support select() and position() operations. That is, their keys can be accessed according to their inorder position and logarithmic time. This allows to treat the tree as if it was an array.
This tree type is unbeatable when there are splits and and especially joins operations on very large data sets. Other tree types perform the join of independent data sets in
, where
and
are the size of two data sets, while the randomized approach takes
.
The class internally uses the gsl random number generator of GSL - GNU Scientific Library. By default, the Mersene twister is used and the seed is taken from system time.
template<template< typename > class NodeType, typename Key, class Compare>
| std::pair<long, Node*> Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::find_position |
( |
const Key & |
key | ) |
|
|
inlinenoexcept |
Find the inorder position of a key in the tree.
find_position(key) determines the inorder position that has or had key in the tree. Themethod return a tuple with a position and a node pointer.
If key is found then its inorder position is returned along with a pointer to the node containing it.
Otherwise, the the tuple returns the position that would have key if this was in the tree and the parent node that the key would had. At this regard, there are three cases:
- if
key is lesser than the minimum key of tree, then first is -1 and the node is one with the smallest key.
- If
key is greater than the maximum key in the tree, then first is the number of keys and the node is one with the maximum key in the tree.
- For any other case, first is the inorder position that would have
key if this was in the tree and second is the node whose key is inmediataly greater than key.
- Parameters
-
- Returns
- a pair with the inorder position and and related node
template<template< typename > class NodeType, typename Key, class Compare>
Join this with t filtering the duplicated keys
join(t, dup) produces a random tree result of join of this and t. The resulting tree is stored in this.
Nodes containing duplicated keys are inserted in the randomized tree dup. The nodes could belong to any of two trees
- Parameters
-
| [in] | t | ramdomized tree to join with this |
| [out] | dup | ramdomized tree where nodes containing duplicated keys are inserted |