aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
binSearchTree.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Basic binary search trees.
25  *
26  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 
29 #ifndef GUM_BIN_SEARCH_TREE_H
30 #define GUM_BIN_SEARCH_TREE_H
31 
32 #include <agrum/agrum.h>
33 
34 #include <agrum/tools/core/binTreeNode.h>
35 
36 namespace gum {
37 
38 #ifndef DOXYGEN_SHOULD_SKIP_THIS
39  // classes provided/used by this header
40  template < typename Val, class Cmp, class Node >
41  class BinSearchTree;
42 
43  template < typename Val, class Cmp, class Node >
45 #endif // DOXYGEN_SHOULD_SKIP_THIS
46 
47  // ===========================================================================
48  // === GENERIC BINARY SEARCH TREE ===
49  // ===========================================================================
50 
51  /**
52  * @class BinSearchTree
53  * @headerfile binSearchTree.h <agrum/tools/core/binSearchTree.h>
54  * @brief A generic binary search tree.
55  * @ingroup basicstruct_group
56  *
57  * @tparam Val The values type to store in the binary search tree.
58  * @tparam Cmp The comparator for sorting the binary search tree.
59  * @tparam Node The nodes type used to store values in the binary search
60  * tree.
61  *
62  */
63  template < typename Val, class Cmp = std::less< Val >, class Node = BinTreeNode< Val > >
64  class BinSearchTree {
65  public:
66  /// @brief Alias for gum::BinSearchTree iterators
67  /// @{
68  typedef BinSearchTreeIterator< Val, Cmp, Node > iterator;
69  typedef BinSearchTreeIterator< Val, Cmp, Node > const_iterator;
70  /// @}
71 
72  // ============================================================================
73  /// @name Class constructors and destructors
74  // ============================================================================
75  /// @{
76 
77  /**
78  * @brief Basic constructor: returns an empty binary search tree.
79  * @param uniqueness_policy Allows (false) or disables (true) the binary
80  * tree uniqueness.
81  *
82  * It is possible for the binary tree to have multiple instances of the
83  * same value within the tree.
84  */
85  explicit BinSearchTree(bool uniqueness_policy = false);
86 
87  /**
88  * @brief Copy constructor.
89  * @param from The gum::BinSearchTree to copy.
90  */
91  BinSearchTree(const BinSearchTree< Val, Cmp, Node >& from);
92 
93  /**
94  * @brief Class destructor.
95  */
96  virtual ~BinSearchTree();
97 
98  /// @}
99  // ============================================================================
100  /// @name Class operators
101  // ============================================================================
102  /// @{
103 
104  /**
105  * @brief Copy operator.
106  * @param from The gum::BinSearchTree to copy.
107  * @return Returns this gum::BinSearchTree.
108  */
109  BinSearchTree< Val, Cmp, Node >& operator=(const BinSearchTree< Val, Cmp, Node >& from);
110 
111  /// @}
112  // ============================================================================
113  /// @name Class iterators
114  // ============================================================================
115  /// @{
116 
117  /**
118  * @brief Begin iterator.
119  * @return Returns an iterator at the beginning of the gum::BinSearchTree.
120  */
121  /// @{
122  iterator begin();
123  const_iterator begin() const;
124  /// @}
125 
126  /**
127  * @brief Reverse iterator.
128  * @return Returns an iterator at the beginning of the gum::BinSearchTree for
129  * reverse iteration.
130  */
131  /// @{
132  iterator rbegin();
133  const_iterator rbegin() const;
134  /// @}
135 
136  /**
137  * @brief End iterator.
138  * @return Returns an iterator at the end of the gum::BinSearchTree.
139  */
140  /// @{
141  const iterator& end();
142  const const_iterator& end() const;
143  /// @}
144 
145  /**
146  * @brief Reverse end iterator.
147  * @return Returns an iterator at the end of the gum::BinSearchTree for
148  * reverse iteration.
149  */
150  /// @{
151  const iterator& rend();
152  const const_iterator& rend() const;
153  /// @}
154 
155  /**
156  * @brief Returns an iterator at the root of the tree.
157  * @return Returns an iterator at the root of the tree.
158  */
159  /// @{
160  iterator root();
161  const_iterator root() const;
162  /// @}
163 
164  /// @}
165  // ============================================================================
166  /// @name Class Accessors and Modifiers
167  // ============================================================================
168  /// @{
169 
170  /**
171  * @brief Returns the value of the root of the tree.
172  * @return Returns the value of the root of the tree.
173  * @throw NotFound Raised if the tree is empty.
174  */
175  const Val& rootValue() const;
176 
177  /**
178  * @brief Returns the value of the leftmost node with the minimal key in
179  * the tree.
180  * @return Returns the value of the leftmost node with the minimal key in
181  * the tree.
182  * @throw NotFound Raised if the tree is empty.
183  */
184  const Val& minValue() const;
185 
186  /**
187  * @brief Returns the value of the rightmost node with the maximal key in
188  * the tree.
189  * @return Returns the value of the rightmost node with the maximal key in
190  * the tree.
191  * @throw NotFound Raised if the tree is empty/
192  */
193  const Val& maxValue() const;
194 
195  /**
196  * @brief Creates a copy of the value, insert it in the tree and returns
197  * the copy value.
198  *
199  * When elements are inserted into binary search trees, this is actually
200  * copies that are inserted. Thus, the method returns the newly created
201  * copy, so that the user may reference it.
202  *
203  * @param val The value added by copy.
204  * @return Returns a reference over copy added in the gum::BinSearchTree.
205  * @throw DuplicateElement Raised if the binary tree already contains the
206  * value and the uniqueness property is set to true.
207  */
208  const Val& insert(const Val& val);
209 
210  /**
211  * @brief Erase the leftmost node with the given (key,val) pair.
212  * @param val The value to remove.
213  * @throws NotFound Raised if we could not find the node.
214  */
215  void erase(const Val& val);
216 
217  /**
218  * @brief Erase the node pointed to by the iterator.
219  *
220  * If we could not find the node, then nothing happens. In particular, no
221  * exception is raised.
222  *
223  * @param iter The iterator pointing toward the value to remove.
224  */
225  void erase(const iterator& iter);
226 
227  /**
228  * @brief Returns true if the gum::BinSearchTree contains the value.
229  * @param val The value tested for existence.
230  * @return Returns true if the gum::BinSearchTree contains the value.
231  */
232  bool contains(const Val& val) const;
233 
234  /**
235  * @brief Removes all the elements from the gum::BinSearchTree.
236  */
237  void clear();
238 
239  /**
240  * @brief Returns the number of elements in the binary search tree.
241  * @return Returns the number of elements in the binary search tree.
242  */
243  Size size() const;
244 
245  /**
246  * @brief Indicates whether the gum::BinSearchTree search tree is empty.
247  * @return Returns true if the gum::BinSearchTree is empty.
248  */
249  bool empty() const;
250 
251  /**
252  * @brief Displays the content of the tree, in increasing order w.r.t.
253  * Cmp.
254  * @return Returns the content of the tree in a string.
255  */
256  virtual std::string toString() const;
257 
258  /// @}
259  // ============================================================================
260  /// @name Fine tuning
261  // ============================================================================
262  /// @{
263 
264  /**
265  * @brief Returns the current uniqueness policy.
266  * @return Returns the current uniqueness policy.
267  */
268  bool uniquenessPolicy() const;
269 
270  /**
271  * @brief Enables the user to change dynamically the policy for checking
272  * whether there can exist several identical elements in the binary tree.
273  *
274  * By default, trees can store several times the same element. However, for
275  * some applications, we should ensure that all elements in the binary
276  * search tree are distinct.
277  *
278  * @warning When setting the policy to "uniqueness", the function does not
279  * check whether the tree already contains identical elements. It thus only
280  * ensures that elements inserted from now on do not already belong to the
281  * tree.
282  *
283  * @param new_policy Set the uniqueness policy on or off.
284  */
285  void setUniquenessPolicy(const bool new_policy);
286 
287  /// @}
288 
289  protected:
290  /// The root node of the tree.
291  Node* root_;
292 
293  /// The comparison function.
294  Cmp cmp_;
295 
296  /// The list of iterators pointing to the binary search tree.
298 
299  /// The uniqueness property: whether the same value can appear multiple
300  /// times.
301  mutable bool uniqueness_policy_;
302 
303  /// The number of elements stored in the tree.
305 
306  /**
307  * @brief Pseudo static iterator.
308  *
309  * The end and rend iterators are constructed only once per binary search
310  * tree so as to optimize for(iter = begin();iter != end(); iter++) loops:
311  * this will avoid creating objects end and rend each time we pass in the
312  * loop.
313  */
315 
316  /// @brief To speed-up accesses.
317  /// @{
318  friend class BinSearchTreeIterator< Val, Cmp, Node >;
319  /// @}
320 
321  /**
322  * @brief A method for recursively copying the contents of a BinSearchTree.
323  *
324  * @warning This function produces a tree with precisely the same structure
325  * as that passed in argument (node). Hence, this should be used only when
326  * copying binary search trees storing data w.r.t. the same weak order Cmp.
327  *
328  * @param root_from The root of the tree to be copied.
329  * @param parent The node that should be the parent of the copy.
330  * @param dir The direction of the edge parent->copy.
331  */
332  Node* copy_(Node* root_from, Node* parent = 0, BinTreeDir dir = BinTreeDir::LEFT_CHILD);
333 
334  /**
335  * @brief Returns the smallest node w.r.t. order Cmp in the subtree rooted
336  * at node.
337  * @param node The root for looking for the the smallest node.
338  * @return Returns the smallest node.
339  */
340  Node* minNode_(Node* node) const;
341 
342  /**
343  * @brief Returns the greatest node w.r.t. order Cmp in the subtree rooted
344  * at node.
345  * @param node The root for looking for the the greatest node.
346  * @return Returns the greatest node.
347  */
348  Node* maxNode_(Node* node) const;
349 
350  /**
351  * @brief Returns the next node according to the weak ordering Cmp.
352  * @param node The node for which the sucessor is returned.
353  * @return Returns the next node according to the weak ordering Cmp.
354  */
355  Node* succNode_(Node* node) const;
356 
357  /**
358  * @brief Returns the previous node according to weak ordering Cmp.
359  * @param node The node for which the previous node is returned.
360  * @return Returns the previous node according to the weak ordering Cmp.
361  */
362  Node* prevNode_(Node* node) const;
363 
364  /**
365  * @brief Returns the node containing a given value.
366  * @param val The value of the node to return.
367  * @return Returns the node containing a given value (0 if the value cannot
368  * be found).
369  */
370  Node* getNode_(const Val& val) const;
371 
372  ///
373  /**
374  * @brief A method for recursively deleting a subtree of the
375  * gum::BinSearchTree.
376  *
377  * Note that this method does not update the iterators pointing to nodes of
378  * the subtree. These should be cleared before deleteSubTree_ is called.
379  *
380  * @param node The root of the subtree to delete.
381  */
382  void deleteSubTree_(Node* node);
383 
384  /**
385  * @brief Erase the node passed in argument.
386  * @param node The Node to erase.
387  */
388  virtual void erase_(Node* node);
389 
390  private:
391  /**
392  * @brief Erase a node with two children.
393  *
394  * This is used by gum::BinSearchTree::erase_(Node*).
395  * @param node The node to erase.
396  */
397  void _eraseWithTwoChildren_(Node* node);
398 
399  protected:
400  /**
401  * @brief Creates a copy of the value, insert it in the gum::BinSearchTree
402  * and returns the copy value.
403  *
404  * When elements are inserted into gum::BinSearchTree, this is actually
405  * copies that are inserted. Thus, the method returns the node containing
406  * the newly created copy, so that the user may reference the new copy.
407  *
408  * @warning this method is actually the implementation of method insert. It
409  * is used to speed-up insertions in terminal classes such as AVL trees.
410  * @throw DuplicateElement exception is raised if the binary tree already
411  * contains the value and the uniqueness property is set to true.
412  *
413  * @param val The value added by copy.
414  * @return Returns the node containing the newly created copy.
415  */
416  virtual Node* insert_(const Val& val);
417 
418  private:
419  /**
420  * @brief Update all iterators when a given node is deleted.
421  * @param node The node that is erased.
422  */
423  void _updateEraseIterators_(Node* node);
424  };
425 
426  // ===========================================================================
427  // === GENERIC BINARY SEARCH TREE ITERATORS ===
428  // ===========================================================================
429 
430  /**
431  * @class BinSearchTreeIterator
432  * @headerfile binSearchTree.h <agrum/tools/core/binSearchTree.h>
433  * @brief A Generic binary search tree.
434  * @ingroup basicstruct_group
435  *
436  * @tparam Val The values type to store in the binary search tree.
437  * @tparam Cmp The compatator for sorting the binary search tree.
438  * @tparam Node The nodes type used to store values in the binary search
439  * tree.
440  */
441  template < typename Val, class Cmp, class Node >
443  public:
444  // ============================================================================
445  /// Class Constructors and Destructors
446  // ============================================================================
447  ///@{
448 
449  /**
450  * @brief Basic constructor: returns an iterator pointing toward nothing.
451  */
453 
454  /**
455  * @brief Copy constructor: creates an iterator pointing toward the same
456  * tree.
457  * @param from The gum::BinSearchTreeIterator to copy.
458  */
459  BinSearchTreeIterator(const BinSearchTreeIterator< Val, Cmp, Node >& from);
460 
461  /// @brief Class destructor.
463 
464  ///@}
465  // ============================================================================
466  /// Class operators
467  // ============================================================================
468  ///@{
469 
470  /**
471  * @brief Copy operator.
472  * @param from the gum::BinSearchTreeIterator to copy.
473  * @return Returns this gum::BinSearchTreeIterator.
474  */
475  BinSearchTreeIterator< Val, Cmp, Node >&
476  operator=(const BinSearchTreeIterator< Val, Cmp, Node >& from);
477 
478  /**
479  * @brief Returns the value pointed to by the iterator.
480  * @return Returns the value pointed to by the iterator.
481  * @throw UndefinedIteratorValue Raised if the iterator does not point to a
482  * valid node of the tree.
483  */
484  const Val& operator*() const;
485 
486  /**
487  * @brief Point the iterator to the next value in the binary search tree.
488  *
489  * A binary search tree stores data according to a complete weak order <=.
490  * A ++ operation on an iterator makes the latter point on the next value
491  * in the tree w.r.t. ordering <=.
492  *
493  * Loops are guaranteed to parse the whole binary search tree as long as no
494  * element is added to or deleted from the tree while being in the loop.
495  * Deleting elements during the loop is guaranteed to never produce a
496  * segmentation fault.
497  *
498  * @code
499  * for (iter = tree.begin(); iter != tree.end(); ++iter) {
500  * // some code
501  * }
502  * @endcode
503  *
504  * @return Returns this gum::BinSearchTreeIterator.
505  */
506  BinSearchTreeIterator< Val, Cmp, Node >& operator++();
507 
508  /**
509  * @brief Point the iterator to the preceding value in the binary search
510  * tree.
511  *
512  * A binary search tree stores data according to a complete weak order <=.
513  * A -- operation on an iterator makes the latter point on the preceding
514  * value in the tree w.r.t. ordering <=.
515  *
516  * Loops are guaranteed to parse the whole binary search tree as long as no
517  * element is added to or deleted from the tree while being in the loop.
518  * Deleting elements during the loop is guaranteed to never produce a
519  * segmentation fault.
520  *
521  * @code
522  * for (iter = tre.rbegin(); iter != tree.rend(); --iter) {
523  * // some code
524  * }
525  * @endcode
526  */
527  BinSearchTreeIterator< Val, Cmp, Node >& operator--();
528 
529  /**
530  * @brief Checks whether two iterators are pointing toward different
531  * elements.
532  * @param from The gum::BinSearchTreeIterator to test for inequality.
533  * @return Returns true if the two gum::BinSearchTreeIterator are
534  * different.
535  */
536  bool operator!=(const BinSearchTreeIterator< Val, Cmp, Node >& from) const;
537 
538  /**
539  * @brief Checks whether two iterators are pointing toward identical
540  * elements.
541  * @param from The gum::BinSearchTreeIterator to test for equality.
542  * @return Returns true if the two gum::BinSearchTreeIterator are
543  * equal.
544  */
545  bool operator==(const BinSearchTreeIterator< Val, Cmp, Node >& from) const;
546 
547  ///@}
548  // ############################################################################
549  /// @name Accessors / Modifiers
550  // ############################################################################
551  /// @{
552 
553  /**
554  * @brief Makes the iterator move to its parent node.
555  * @return Return this gum::BinSearchTreeIterator.
556  */
557  BinSearchTreeIterator< Val, Cmp, Node >& up();
558 
559  /**
560  * @brief Makes the iterator move to the left child of the node it points
561  * to.
562  * @return Return this gum::BinSearchTreeIterator.
563  */
564  BinSearchTreeIterator< Val, Cmp, Node >& downLeft();
565 
566  /**
567  * @brief Makes the iterator move to the right child of the node it points
568  * to.
569  * @return Return this gum::BinSearchTreeIterator.
570  */
571  BinSearchTreeIterator< Val, Cmp, Node >& downRight();
572 
573  /**
574  * @brief Detach the iterator from its current tree (if any) and reset it.
575  */
576  void clear();
577 
578  ///@}
579 
580  protected:
581  /// The current node pointed to by the iterator.
582  Node* node_;
583 
584  /// The next node to be used when node_=0 (if a ++ operator is applied).
585  Node* next_node_;
586 
587  /// The preceding node to be used when node_=0 (if a -- operator is
588  /// applied).
589  Node* prev_node_;
590 
591  /// The parent to be used when node_=0 (if operation up is applied).
592  Node* parent_;
593 
594  /// The left child to be used when node_=0 and leftdown() is applied.
595  Node* left_child_;
596 
597  /// The right child to be used when node_=0 and rightdown() is applied.
599 
600  /// The binary search tree pointed to by the iterator.
601  BinSearchTree< Val, Cmp, Node >* tree_;
602 
603  /// The next iterator in the list of iterators of the binSearchTree.
604  BinSearchTreeIterator< Val, Cmp, Node >* next_iter_;
605 
606  private:
607  /// To speed-up accesses.
608  /// @{
609  friend class BinSearchTree< Val, Cmp, Node >;
610  /// @}
611 
612  /**
613  * @brief A function called to initialize an iterator.
614  *
615  * Assuming that the iterator has been constructed using the default
616  * constructor (i.e., it points toward no binary search tree), this method
617  * make it point toward one tree and, if needed, add it to the set of
618  * iterators of the tree.
619  *
620  * @param tree The gum::BinSearchTree to iterate on.
621  * @param current_node The node pointed by this iterator.
622  * @param add_to_iterator_list Add this iterator to the iterator list.
623  */
624  void initialize_(const BinSearchTree< Val, Cmp, Node >* tree,
625  const Node* current_node,
626  bool add_to_iterator_list);
627 
628  /**
629  * @brief a method to detach the current iterator from its tree's
630  * iterator's list.
631  */
632  void detachFromTree_();
633  };
634 
635 } /* namespace gum */
636 
637 
638 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
639 extern template class gum::BinSearchTree< int >;
640 #endif
641 
642 
643 // always include the template implementations
644 #include <agrum/tools/core/binSearchTree_tpl.h>
645 
646 #endif // GUM_BIN_SEARCH_TREE_H
virtual ~BinSearchTree()
Class destructor.
void detachFromTree_()
a method to detach the current iterator from its tree&#39;s iterator&#39;s list.
A generic binary search tree.
Definition: binSearchTree.h:64
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)
Definition: set_tpl.h:643
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.
Definition: binSearchTree.h:69
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.
Definition: binSearchTree.h:68
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.