![]() |
aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
|
AVL binary search tree. More...
#include <agrum/base/core/AVLTree.h>
Public Types | |
| using | value_type = Val |
| Types for STL compliance. | |
| using | reference = Val& |
| Types for STL compliance. | |
| using | const_reference = const Val& |
| Types for STL compliance. | |
| using | pointer = Val* |
| Types for STL compliance. | |
| using | const_pointer = const Val* |
| Types for STL compliance. | |
| using | iterator = AVLTreeIterator< Val, Cmp > |
| Types for STL compliance. | |
| using | iterator_safe = AVLTreeIteratorSafe< Val, Cmp > |
| Types for STL compliance. | |
| using | reverse_iterator = AVLTreeReverseIterator< Val, Cmp > |
| Types for STL compliance. | |
| using | reverse_iterator_safe = AVLTreeReverseIteratorSafe< Val, Cmp > |
| Types for STL compliance. | |
| using | AVLNode = AVLTreeNode< Val > |
| Types for STL compliance. | |
Public Member Functions | |
Constructors / Destructors | |
| AVLTree (const Cmp &compare=Cmp()) | |
| Basic constructor. | |
| AVLTree (std::initializer_list< Val > list) | |
| Initializer list constructor. | |
| AVLTree (const AVLTree< Val, Cmp > &from) | |
| Copy constructor. | |
| AVLTree (AVLTree< Val, Cmp > &&from) noexcept | |
| Move constructor. | |
| ~AVLTree () | |
| Class destructor. | |
Operators | |
| AVLTree< Val, Cmp > & | operator= (const AVLTree< Val, Cmp > &from) |
| Copy operator. | |
| AVLTree< Val, Cmp > & | operator= (AVLTree< Val, Cmp > &&from) noexcept |
| Move operator. | |
Accessors / Modifiers | |
| Size | size () const noexcept |
| Returns the number of elements in the tree. | |
| bool | empty () const noexcept |
| Indicates whether the tree is empty. | |
| bool | contains (const value_type &val) const |
| Indicates whether the tree contains a given value. | |
| bool | exists (const value_type &val) const |
| Alias of contains: indicates whether the tree contains a given value. | |
| const value_type & | highestValue () const |
| returns the max element (w.r.t. Cmp) in the tree | |
| const value_type & | lowestValue () const |
| returns the min element (w.r.t. Cmp) in the tree | |
| const value_type & | insert (const value_type &val) |
| adds (by copy) a new element into the tree | |
| const value_type & | insert (value_type &&val) |
| adds (by move) a new element into the tree | |
| template<typename... Args> | |
| const value_type & | emplace (Args &&... args) |
| emplace a new element into the tree | |
| void | erase (const value_type &val) |
| remove an element from the tree | |
| void | erase (iterator_safe &iter) |
| remove the element pointed to by an iterator | |
| void | erase (reverse_iterator_safe &iter) |
| remove the element pointed to by an iterator | |
| void | clear () |
| remove all the elements in the tree | |
| std::string | toString () const |
| returns a string with the content of the tree, order from the lowest to the highest element | |
Iterators | |
| iterator | begin () const |
| returns a new iterator pointing to the minimal element of the tree | |
| constexpr const iterator & | end () const |
| returns an iterator pointing just after the maximal element | |
| reverse_iterator | rbegin () const |
| returns a new iterator pointing to the maximal element of the tree | |
| constexpr const reverse_iterator & | rend () const |
| returns an iterator pointing just before the minimal element | |
| iterator_safe | beginSafe () |
| returns a new safe iterator pointing to the minimal element of the tree | |
| constexpr const iterator_safe & | endSafe () const |
| returns a safe iterator pointing just after the maximal element | |
| reverse_iterator_safe | rbeginSafe () |
| returns a safe iterator pointing to the maximal element of the tree | |
| constexpr const reverse_iterator_safe & | rendSafe () const |
| returns a safe iterator pointing just before the minimal element | |
Protected Member Functions | |
| AVLNode * | lowestNode_ () const noexcept |
| returns the node containing the lowest element of the tree | |
| AVLNode * | highestNode_ () const noexcept |
| returns the node containing the highest element of the tree | |
| AVLNode * | rightRotation_ (AVLNode *node_q) |
| rotate the subtree rooted at q to the right | |
| AVLNode * | leftRotation_ (AVLNode *node_p) |
| rotate the subtree rooted at p to the left | |
| void | rebalanceTree_ (AVLNode *node) |
| rebalance the tree moving up recursively from a given node | |
| AVLNode * | removeNodeFromTree_ (AVLNode *node) |
| remove a node from the tree and returns the node that was actually removed | |
| void | erase_ (AVLNode *node) |
| remove a node from the tree and free memory | |
| const value_type & | insert_ (AVLNode *node) |
| insert a node into the tree | |
| void | insertIntoSafeList_ (iterator_safe *iter) |
| register a new safe iterator | |
| void | removeFromSafeList_ (iterator_safe *iter) |
| unregister a safe iterator | |
Static Protected Member Functions | |
| static AVLNode * | copySubtree_ (const AVLNode *from_node, AVLNode *new_parent) |
| copies recursively a subtree of the AVL tree | |
| static void | deleteSubtree_ (AVLNode *subtree_root_node) |
| deletes recursively a subtree of the AVL tree | |
Protected Attributes | |
| AVLNode * | root_node_ {nullptr} |
| the root of the AVL tree | |
| AVLNode * | lowest_node_ {nullptr} |
| the node containing the lowest element | |
| AVLNode * | highest_node_ {nullptr} |
| the node containing the highest element | |
| Size | nb_elements_ {Size(0)} |
| the number of elements in the tree | |
| bool | owns_nodes_ {true} |
| indicates whether the tree owns its nodes. If not, it won't delete them | |
| Cmp | cmp_ |
| the comparison function | |
| std::vector< iterator_safe * > | safe_iterators_ |
| The list of safe iterators and reverse iterators used by the AVL tree. | |
| friend | iterator |
| make the iterators access to the AVLNodes | |
| friend | reverse_iterator |
| friend | iterator_safe |
| friend | reverse_iterator_safe |
AVL binary search tree.
| Val | The type of the elements stored into the tree. |
| Cmp | The function used for sorting the elements. queues. |
| using gum::AVLTree< Val, Cmp >::AVLNode = AVLTreeNode< Val > |
| using gum::AVLTree< Val, Cmp >::const_pointer = const Val* |
| using gum::AVLTree< Val, Cmp >::const_reference = const Val& |
| using gum::AVLTree< Val, Cmp >::iterator = AVLTreeIterator< Val, Cmp > |
| using gum::AVLTree< Val, Cmp >::iterator_safe = AVLTreeIteratorSafe< Val, Cmp > |
| using gum::AVLTree< Val, Cmp >::pointer = Val* |
| using gum::AVLTree< Val, Cmp >::reference = Val& |
| using gum::AVLTree< Val, Cmp >::reverse_iterator = AVLTreeReverseIterator< Val, Cmp > |
| using gum::AVLTree< Val, Cmp >::reverse_iterator_safe = AVLTreeReverseIteratorSafe< Val, Cmp > |
| using gum::AVLTree< Val, Cmp >::value_type = Val |
|
explicit |
Basic constructor.
Creates an empty tree.
| compare | A function taking two elements in argument, say e1 and e2, and returning a Boolean indicating whether e1 < e2, i.e., whether e1 should be "on the left of" e2. |
Referenced by AVLTree(), AVLTree(), operator=(), and operator=().
|
explicit |
Initializer list constructor.
A default comparison function is provided.
| list | The initializer list. |
| gum::AVLTree< Val, Cmp >::AVLTree | ( | const AVLTree< Val, Cmp > & | from | ) |
Copy constructor.
| from | The gum::AVLTree to copy. |
References AVLTree().
|
noexcept |
Move constructor.
| from | The gum::AVLTree to move. |
References AVLTree().
| gum::AVLTree< Val, Cmp >::~AVLTree | ( | ) |
Class destructor.
| iterator gum::AVLTree< Val, Cmp >::begin | ( | ) | const |
| iterator_safe gum::AVLTree< Val, Cmp >::beginSafe | ( | ) |
returns a new safe iterator pointing to the minimal element of the tree
References beginSafe().
Referenced by beginSafe().
| void gum::AVLTree< Val, Cmp >::clear | ( | ) |
| bool gum::AVLTree< Val, Cmp >::contains | ( | const value_type & | val | ) | const |
Indicates whether the tree contains a given value.
| val | The value to look for. |
References contains().
Referenced by contains().
|
staticprotected |
copies recursively a subtree of the AVL tree
| from_node | the root node of the subtree that we copy recursively |
| new_parent | the parent of the root node of the copied subtree |
References copySubtree_().
Referenced by copySubtree_().
|
staticprotected |
deletes recursively a subtree of the AVL tree
References deleteSubtree_().
Referenced by deleteSubtree_().
| const value_type & gum::AVLTree< Val, Cmp >::emplace | ( | Args &&... | args | ) |
|
noexcept |
|
constexpr |
|
constexpr |
| void gum::AVLTree< Val, Cmp >::erase | ( | const value_type & | val | ) |
remove an element from the tree
If the element does not exist, the function does nothing. In particular, it does not raise any exception.
For speed reasons, if you already have an iterator pointing to val, prefer using erase(iterator) rather than erase(val).
References erase().
Referenced by erase(), erase(), and erase().
| void gum::AVLTree< Val, Cmp >::erase | ( | iterator_safe & | iter | ) |
remove the element pointed to by an iterator
References erase().
| void gum::AVLTree< Val, Cmp >::erase | ( | reverse_iterator_safe & | iter | ) |
remove the element pointed to by an iterator
References erase().
|
protected |
| bool gum::AVLTree< Val, Cmp >::exists | ( | const value_type & | val | ) | const |
|
protectednoexcept |
returns the node containing the highest element of the tree
References highestNode_().
Referenced by highestNode_().
| const value_type & gum::AVLTree< Val, Cmp >::highestValue | ( | ) | const |
returns the max element (w.r.t. Cmp) in the tree
| NotFound | Raised if the tree is empty |
References highestValue().
Referenced by highestValue().
| const value_type & gum::AVLTree< Val, Cmp >::insert | ( | const value_type & | val | ) |
| const value_type & gum::AVLTree< Val, Cmp >::insert | ( | value_type && | val | ) |
adds (by move) a new element into the tree
References insert().
|
protected |
|
protected |
register a new safe iterator
References insertIntoSafeList_().
Referenced by insertIntoSafeList_().
|
protected |
rotate the subtree rooted at p to the left
References leftRotation_().
Referenced by leftRotation_().
|
protectednoexcept |
returns the node containing the lowest element of the tree
| const value_type & gum::AVLTree< Val, Cmp >::lowestValue | ( | ) | const |
returns the min element (w.r.t. Cmp) in the tree
| NotFound | Raised if the tree is empty |
References lowestValue().
Referenced by lowestValue().
|
noexcept |
Move operator.
| from | The gum::AVLTree to move. |
References AVLTree().
| AVLTree< Val, Cmp > & gum::AVLTree< Val, Cmp >::operator= | ( | const AVLTree< Val, Cmp > & | from | ) |
Copy operator.
| from | The gum::AVLTree to copy. |
References AVLTree().
| reverse_iterator gum::AVLTree< Val, Cmp >::rbegin | ( | ) | const |
| reverse_iterator_safe gum::AVLTree< Val, Cmp >::rbeginSafe | ( | ) |
returns a safe iterator pointing to the maximal element of the tree
References rbeginSafe().
Referenced by rbeginSafe().
|
protected |
rebalance the tree moving up recursively from a given node
References rebalanceTree_().
Referenced by rebalanceTree_().
|
protected |
unregister a safe iterator
References removeFromSafeList_().
Referenced by removeFromSafeList_().
|
protected |
remove a node from the tree and returns the node that was actually removed
References removeNodeFromTree_().
Referenced by removeNodeFromTree_().
|
constexpr |
|
constexpr |
returns a safe iterator pointing just before the minimal element
References rendSafe().
Referenced by rendSafe().
|
protected |
rotate the subtree rooted at q to the right
References rightRotation_().
Referenced by rightRotation_().
|
noexcept |
Returns the number of elements in the tree.
| std::string gum::AVLTree< Val, Cmp >::toString | ( | ) | const |
returns a string with the content of the tree, order from the lowest to the highest element
References toString().
Referenced by toString().
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |