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