29 #ifndef GUM_BIN_SEARCH_TREE_H 30 #define GUM_BIN_SEARCH_TREE_H 32 #include <agrum/agrum.h> 34 #include <agrum/tools/core/binTreeNode.h> 38 #ifndef DOXYGEN_SHOULD_SKIP_THIS 40 template <
typename Val,
class Cmp,
class Node >
43 template <
typename Val,
class Cmp,
class Node >
208 const Val&
insert(
const Val& val);
215 void erase(
const Val& val);
232 bool contains(
const Val& val)
const;
370 Node*
getNode_(
const Val& val)
const;
388 virtual void erase_(Node* node);
416 virtual Node*
insert_(
const Val& val);
441 template <
typename Val,
class Cmp,
class Node >
625 const Node* current_node,
626 bool add_to_iterator_list);
638 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 639 extern template class gum::BinSearchTree<
int >;
644 #include <agrum/tools/core/binSearchTree_tpl.h> virtual ~BinSearchTree()
Class destructor.
void detachFromTree_()
a method to detach the current iterator from its tree's iterator's list.
A generic binary search tree.
bool uniqueness_policy_
The uniqueness property: whether the same value can appear multiple times.
BinSearchTree(const BinSearchTree< Val, Cmp, Node > &from)
Copy constructor.
Node * parent_
The parent to be used when node_=0 (if operation up is applied).
BinSearchTreeIterator< Val, Cmp, Node > & operator--()
Point the iterator to the preceding value in the binary search tree.
void _eraseWithTwoChildren_(Node *node)
Erase a node with two children.
Cmp cmp_
The comparison function.
Node * prevNode_(Node *node) const
Returns the previous node according to weak ordering Cmp.
const_iterator rbegin() const
Reverse iterator.
Size size() const
Returns the number of elements in the binary search tree.
Node * minNode_(Node *node) const
Returns the smallest node w.r.t.
INLINE void emplace(Args &&... args)
void initialize_(const BinSearchTree< Val, Cmp, Node > *tree, const Node *current_node, bool add_to_iterator_list)
A function called to initialize an iterator.
Node * next_node_
The next node to be used when node_=0 (if a ++ operator is applied).
BinSearchTreeIterator< Val, Cmp, Node > & downRight()
Makes the iterator move to the right child of the node it points to.
void _updateEraseIterators_(Node *node)
Update all iterators when a given node is deleted.
bool operator==(const BinSearchTreeIterator< Val, Cmp, Node > &from) const
Checks whether two iterators are pointing toward identical elements.
const Val & insert(const Val &val)
Creates a copy of the value, insert it in the tree and returns the copy value.
void clear()
Detach the iterator from its current tree (if any) and reset it.
void deleteSubTree_(Node *node)
A method for recursively deleting a subtree of the gum::BinSearchTree.
iterator iter_end_
Pseudo static iterator.
const const_iterator & rend() const
Reverse end iterator.
BinSearchTreeIterator()
Class Constructors and Destructors.
const const_iterator & end() const
End iterator.
iterator rbegin()
Reverse iterator.
bool operator!=(const BinSearchTreeIterator< Val, Cmp, Node > &from) const
Checks whether two iterators are pointing toward different elements.
const_iterator begin() const
Begin iterator.
BinSearchTreeIterator< Val, Cmp, Node > * next_iter_
The next iterator in the list of iterators of the binSearchTree.
BinSearchTreeIterator< Val, Cmp, Node > const_iterator
Alias for gum::BinSearchTree iterators.
Node * prev_node_
The preceding node to be used when node_=0 (if a – operator is applied).
bool empty() const
Indicates whether the gum::BinSearchTree search tree is empty.
iterator root()
Returns an iterator at the root of the tree.
const Val & minValue() const
Returns the value of the leftmost node with the minimal key in the tree.
BinSearchTreeIterator< Val, Cmp, Node > & operator++()
Point the iterator to the next value in the binary search tree.
Node * root_
The root node of the tree.
const Val & rootValue() const
Returns the value of the root of the tree.
Node * copy_(Node *root_from, Node *parent=0, BinTreeDir dir=BinTreeDir::LEFT_CHILD)
A method for recursively copying the contents of a BinSearchTree.
const Val & maxValue() const
Returns the value of the rightmost node with the maximal key in the tree.
BinSearchTreeIterator< Val, Cmp, Node > & up()
Makes the iterator move to its parent node.
Node * succNode_(Node *node) const
Returns the next node according to the weak ordering Cmp.
Node * right_child_
The right child to be used when node_=0 and rightdown() is applied.
const_iterator root() const
Returns an iterator at the root of the tree.
BinSearchTree(bool uniqueness_policy=false)
Basic constructor: returns an empty binary search tree.
virtual void erase_(Node *node)
Erase the node passed in argument.
Node * left_child_
The left child to be used when node_=0 and leftdown() is applied.
bool uniquenessPolicy() const
Returns the current uniqueness policy.
A Generic binary search tree.
BinSearchTreeIterator< Val, Cmp, Node > iterator
Alias for gum::BinSearchTree iterators.
void clear()
Removes all the elements from the gum::BinSearchTree.
void erase(const iterator &iter)
Erase the node pointed to by the iterator.
BinSearchTree< Val, Cmp, Node > * tree_
The binary search tree pointed to by the iterator.
BinSearchTreeIterator< Val, Cmp, Node > & downLeft()
Makes the iterator move to the left child of the node it points to.
const iterator & rend()
Reverse end iterator.
void erase(const Val &val)
Erase the leftmost node with the given (key,val) pair.
BinSearchTreeIterator(const BinSearchTreeIterator< Val, Cmp, Node > &from)
Copy constructor: creates an iterator pointing toward the same tree.
Size nb_elements_
The number of elements stored in the tree.
void setUniquenessPolicy(const bool new_policy)
Enables the user to change dynamically the policy for checking whether there can exist several identi...
Node * maxNode_(Node *node) const
Returns the greatest node w.r.t.
const iterator & end()
End iterator.
const Val & operator*() const
Returns the value pointed to by the iterator.
Node * node_
The current node pointed to by the iterator.
BinSearchTree< Val, Cmp, Node > & operator=(const BinSearchTree< Val, Cmp, Node > &from)
Copy operator.
virtual Node * insert_(const Val &val)
Creates a copy of the value, insert it in the gum::BinSearchTree and returns the copy value...
iterator * iterator_list_
The list of iterators pointing to the binary search tree.
Node * getNode_(const Val &val) const
Returns the node containing a given value.
BinSearchTreeIterator< Val, Cmp, Node > & operator=(const BinSearchTreeIterator< Val, Cmp, Node > &from)
Class operators.
~BinSearchTreeIterator()
Class destructor.
bool contains(const Val &val) const
Returns true if the gum::BinSearchTree contains the value.
virtual std::string toString() const
Displays the content of the tree, in increasing order w.r.t.
iterator begin()
Begin iterator.