49#ifndef GUM_BIN_SEARCH_TREE_H
50#define GUM_BIN_SEARCH_TREE_H
58#ifndef DOXYGEN_SHOULD_SKIP_THIS
60 template <
typename Val,
class Cmp,
class Node >
63 template <
typename Val,
class Cmp,
class Node >
83 template <
typename Val,
class Cmp = std::less< Val >,
class Node = BinTreeNode< Val > >
461 template <
typename Val,
class Cmp,
class Node >
645 const Node* current_node,
646 bool add_to_iterator_list);
658#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
A Generic binary search tree.
bool operator==(const BinSearchTreeIterator< Val, Cmp, Node > &from) const
Checks whether two iterators are pointing toward identical elements.
bool operator!=(const BinSearchTreeIterator< Val, Cmp, Node > &from) const
Checks whether two iterators are pointing toward different elements.
Node * node_
The current node pointed to by the iterator.
BinSearchTreeIterator< Val, Cmp, Node > & up()
Makes the iterator move to its parent node.
BinSearchTree< Val, Cmp, Node > * tree_
The binary search tree pointed to by the iterator.
Node * next_node_
The next node to be used when node_=nullptr (if a ++ operator is applied).
BinSearchTreeIterator()
Class Constructors and Destructors.
Node * prev_node_
The preceding node to be used when node_=nullptr (if a – operator is applied).
void initialize_(const BinSearchTree< Val, Cmp, Node > *tree, const Node *current_node, bool add_to_iterator_list)
A function called to initialize an iterator.
~BinSearchTreeIterator()
Class destructor.
void clear()
Detach the iterator from its current tree (if any) and reset it.
Node * parent_
The parent to be used when node_=nullptr (if operation up is applied).
BinSearchTreeIterator< Val, Cmp, Node > & operator--()
Point the iterator to the preceding value in the binary search tree.
const Val & operator*() const
Returns the value pointed to by the iterator.
BinSearchTreeIterator< Val, Cmp, Node > & downLeft()
Makes the iterator move to the left child of the node it points to.
void detachFromTree_()
a method to detach the current iterator from its tree's iterator's list.
friend class BinSearchTree< Val, Cmp, Node >
To speed-up accesses.
Node * left_child_
The left child to be used when node_=nullptr and leftdown() is applied.
Node * right_child_
The right child to be used when node_=nullptr and rightdown() is applied.
BinSearchTreeIterator(const BinSearchTreeIterator< Val, Cmp, Node > &from)
Copy constructor: creates an iterator pointing toward the same tree.
BinSearchTreeIterator< Val, Cmp, Node > * next_iter_
The next iterator in the list of iterators of the binSearchTree.
BinSearchTreeIterator< Val, Cmp, Node > & operator++()
Point the iterator to the next value in the binary search tree.
BinSearchTreeIterator< Val, Cmp, Node > & downRight()
Makes the iterator move to the right child of the node it points to.
BinSearchTreeIterator< Val, Cmp, Node > & operator=(const BinSearchTreeIterator< Val, Cmp, Node > &from)
Class operators.
A generic binary search tree.
Size size() const
Returns the number of elements in the binary search tree.
void setUniquenessPolicy(const bool new_policy)
Enables the user to change dynamically the policy for checking whether there can exist several identi...
iterator rbegin()
Reverse iterator.
virtual Node * insert_(const Val &val)
Creates a copy of the value, insert it in the gum::BinSearchTree and returns the copy value.
const_iterator rbegin() const
Reverse iterator.
BinSearchTree(const BinSearchTree< Val, Cmp, Node > &from)
Copy constructor.
virtual std::string toString() const
Displays the content of the tree, in increasing order w.r.t.
BinSearchTreeIterator< Val, Cmp, Node > const_iterator
Alias for gum::BinSearchTree iterators.
const_iterator root() const
Returns an iterator at the root of the tree.
void _updateEraseIterators_(Node *node)
Update all iterators when a given node is deleted.
BinSearchTreeIterator< Val, Cmp, Node > iterator
Alias for gum::BinSearchTree iterators.
Node * getNode_(const Val &val) const
Returns the node containing a given value.
virtual void erase_(Node *node)
Erase the node passed in argument.
Node * root_
The root node of the tree.
bool uniqueness_policy_
The uniqueness property: whether the same value can appear multiple times.
const_iterator begin() const
Begin iterator.
const Val & rootValue() const
Returns the value of the root of the tree.
void deleteSubTree_(Node *node)
A method for recursively deleting a subtree of the gum::BinSearchTree.
const const_iterator & rend() const
Reverse end iterator.
void erase(const iterator &iter)
Erase the node pointed to by the iterator.
const Val & maxValue() const
Returns the value of the rightmost node with the maximal key in the tree.
Node * succNode_(Node *node) const
Returns the next node according to the weak ordering Cmp.
iterator begin()
Begin iterator.
const Val & insert(const Val &val)
Creates a copy of the value, insert it in the tree and returns the copy value.
void _eraseWithTwoChildren_(Node *node)
Erase a node with two children.
bool empty() const
Indicates whether the gum::BinSearchTree search tree is empty.
void clear()
Removes all the elements from the gum::BinSearchTree.
const const_iterator & end() const
End iterator.
const iterator & end()
End iterator.
iterator root()
Returns an iterator at the root of the tree.
Node * minNode_(Node *node) const
Returns the smallest node w.r.t.
friend class BinSearchTreeIterator< Val, Cmp, Node >
To speed-up accesses.
Node * copy_(Node *root_from, Node *parent=0, BinTreeDir dir=BinTreeDir::LEFT_CHILD)
A method for recursively copying the contents of a BinSearchTree.
Node * maxNode_(Node *node) const
Returns the greatest node w.r.t.
Cmp cmp_
The comparison function.
bool uniquenessPolicy() const
Returns the current uniqueness policy.
void erase(const Val &val)
Erase the leftmost node with the given (key,val) pair.
Size nb_elements_
The number of elements stored in the tree.
bool contains(const Val &val) const
Returns true if the gum::BinSearchTree contains the value.
const iterator & rend()
Reverse end iterator.
BinSearchTree< Val, Cmp, Node > & operator=(const BinSearchTree< Val, Cmp, Node > &from)
Copy operator.
virtual ~BinSearchTree()
Class destructor.
iterator * iterator_list_
The list of iterators pointing to the binary search tree.
Node * prevNode_(Node *node) const
Returns the previous node according to weak ordering Cmp.
iterator iter_end_
Pseudo static iterator.
const Val & minValue() const
Returns the value of the leftmost node with the minimal key in the tree.
BinSearchTree(bool uniqueness_policy=false)
Basic constructor: returns an empty binary search tree.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
gum is the global namespace for all aGrUM entities
BinTreeDir
The direction of a given edge in a binary tree.