28 #ifndef GUM_BIN_SEARCH_TREE_H 29 #define GUM_BIN_SEARCH_TREE_H 37 #ifndef DOXYGEN_SHOULD_SKIP_THIS 39 template <
typename Val,
class Cmp,
class Node >
42 template <
typename Val,
class Cmp,
class Node >
43 class BinSearchTreeIterator;
44 #endif // DOXYGEN_SHOULD_SKIP_THIS 62 template <
typename Val,
63 class Cmp = std::less< Val >,
64 class Node = BinTreeNode< Val > >
125 const_iterator
begin()
const;
135 const_iterator
rbegin()
const;
142 const iterator&
end();
144 const const_iterator&
end()
const;
152 const iterator&
rend();
154 const const_iterator&
rend()
const;
163 const_iterator
root()
const;
210 const Val&
insert(
const Val& val);
217 void erase(
const Val& val);
227 void erase(
const iterator& iter);
234 bool contains(
const Val& val)
const;
258 virtual const std::string
toString()
const;
334 Node*
_copy(Node* root_from,
374 Node*
_getNode(
const Val& val)
const;
392 virtual void _erase(Node* node);
420 virtual Node*
_insert(
const Val& val);
445 template <
typename Val,
class Cmp,
class Node >
629 const Node* current_node,
630 bool add_to_iterator_list);
636 void _detachFromTree();
642 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 650 #endif // GUM_BIN_SEARCH_TREE_H iterator _iter_end
Pseudo static iterator.
virtual ~BinSearchTree()
Class destructor.
BinSearchTree< Val, Cmp, Node > * _tree
The binary search tree pointed to by the iterator.
A generic binary search tree.
Node * _getNode(const Val &val) const
Returns the node containing a given value.
Node * _maxNode(Node *node) const
Returns the greatest node w.r.t.
Cmp _cmp
The comparison function.
Size size() const
Returns the number of elements in the binary search tree.
Node * _left_child
The left child to be used when _node=0 and leftdown() is applied.
Node * _next_node
The next node to be used when _node=0 (if a ++ operator is applied).
const Val & insert(const Val &val)
Creates a copy of the value, insert it in the tree and returns the copy value.
gum is the global namespace for all aGrUM entities
iterator rbegin()
Reverse iterator.
Node * _copy(Node *root_from, Node *parent=0, BinTreeDir dir=BinTreeDir::LEFT_CHILD)
A method for recursively copying the contents of a BinSearchTree.
void _deleteSubTree(Node *node)
A method for recursively deleting a subtree of the gum::BinSearchTree.
bool _uniqueness_policy
The uniqueness property: whether the same value can appear multiple times.
BinSearchTreeIterator< Val, Cmp, Node > const_iterator
Alias for gum::BinSearchTree iterators.
BinTreeDir
The direction of a given edge in a binary tree.
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.
const Val & rootValue() const
Returns the value of the root of the tree.
Node * _parent
The parent to be used when _node=0 (if operation up is applied).
const Val & maxValue() const
Returns the value of the rightmost node with the maximal key in the tree.
Node * _right_child
The right child to be used when _node=0 and rightdown() is applied.
Formula operator*(const Formula &a, const Formula &b)
BinSearchTree(bool uniqueness_policy=false)
Basic constructor: returns an empty binary search tree.
bool operator==(const TiXmlString &a, const TiXmlString &b)
Node * _node
The current node pointed to by the iterator.
bool uniquenessPolicy() const
Returns the current uniqueness policy.
A Generic binary search tree.
iterator * _iterator_list
The list of iterators pointing to the binary search tree.
virtual Node * _insert(const Val &val)
Creates a copy of the value, insert it in the gum::BinSearchTree and returns the copy value...
BinSearchTreeIterator< Val, Cmp, Node > iterator
Alias for gum::BinSearchTree iterators.
void __updateEraseIterators(Node *node)
Update all iterators when a given node is deleted.
void clear()
Removes all the elements from the gum::BinSearchTree.
virtual const std::string toString() const
Displays the content of the tree, in increasing order w.r.t.
const iterator & rend()
Reverse end iterator.
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.
void setUniquenessPolicy(const bool new_policy)
Enables the user to change dynamically the policy for checking whether there can exist several identi...
bool operator!=(const TiXmlString &a, const TiXmlString &b)
Node * _prev_node
The preceding node to be used when _node=0 (if a – operator is applied).
const iterator & end()
End iterator.
BinSearchTree< Val, Cmp, Node > & operator=(const BinSearchTree< Val, Cmp, Node > &from)
Copy operator.
BinSearchTreeIterator< Val, Cmp, Node > * _next_iter
The next iterator in the list of iterators of the binSearchTree.
Node * _succNode(Node *node) const
Returns the next node according to the weak ordering Cmp.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
bool contains(const Val &val) const
Returns true if the gum::BinSearchTree contains the value.
virtual void _erase(Node *node)
Erase the node passed in argument.
iterator begin()
Begin iterator.
Node * _minNode(Node *node) const
Returns the smallest node w.r.t.
Node * _root
The root node of the tree.
void __eraseWithTwoChildren(Node *node)
Erase a node with two children.
Node * _prevNode(Node *node) const
Returns the previous node according to weak ordering Cmp.