|
| | avl_tree (const typename base::comparator_type &comparator, const typename base::allocator_type &allocator) |
| | Constructs new AVL tree.
|
| |
| | avl_tree (const avl_tree &other) |
| | Copies another tree.
|
| |
| avl_tree & | operator= (const avl_tree &other) |
| | Copies another tree.
|
| |
| | avl_tree (avl_tree &&other) noexcept |
| | Moves another tree into this one.
|
| |
| avl_tree & | operator= (avl_tree &&other) noexcept |
| | Moves another tree into this one.
|
| |
| | ~avl_tree () noexcept |
| | Destroys the tree.
|
| |
| node_ptr | get_root () const noexcept |
| | Returns the trees root.
|
| |
| node_ptr | find (const key_type &key) const noexcept |
| | Finds a node with the given key, if there isn't any returns a nullptr.
|
| |
| node_ptr | successor (node_ptr node) const noexcept |
| | Returns the successor to the node.
|
| |
| node_ptr | predecessor (node_ptr node) const noexcept |
| | Returns the predecessor to the node.
|
| |
| template<bool lower> |
| node_ptr | bound (const key_type &key) const noexcept |
| | A 2-in-1 function for both lower and upper bounds accessing.
|
| |
| void | clear () noexcept |
| | Erases the whole tree.
|
| |
| template<class TInsertCallback , class TAssignCallback > |
| std::pair< node_ptr, bool > | insert (const key_type &key, TInsertCallback &&insert_callback, TAssignCallback &&assign_callback) |
| | Inserts an item to the tree.
|
| |
| template<class TInsertCallback > |
| std::pair< node_ptr, bool > | insert (const key_type &key, TInsertCallback &&insert_callback) |
| | Inserts an item to the tree.
|
| |
| void | erase (node_ptr node) noexcept |
| | Erases the node.
|
| |
| base::size_type | size () const noexcept |
| | Returns the current number of nodes.
|
| |
| int | get_height () const |
| | Returns the current height of the tree.
|
| |
| std::string | to_dot (bool print_invis) const |
| | Returns the dot representation of the tree.
|
| |
| template<class TInsertCallback , class TAssignCallback > |
| std::pair< typename avl_tree< TKey, TItem, TKeyComp, TAlloc >::node_ptr, bool > | insert (const key_type &key, TInsertCallback &&insert_callback, TAssignCallback &&assign_callback) |
| |
| | avl_tree_base (const comparator_type &comparator, const allocator_type &allocator) |
| |
| | avl_tree_base (comparator_type &&comparator, allocator_type &&allocator) noexcept |
| |
| virtual | ~avl_tree_base ()=0 |
| |
| node_alloc_type | get_allocator () const noexcept |
| | Returns the associated allocator.
|
| |
template<class TKey, class TItem, class TKeyComp, class TAlloc>
class datastructures::detail::avl_tree< TKey, TItem, TKeyComp, TAlloc >
AVL tree implementation.
It should keep a minimal interface, basically supports only insertion, deletion, basic access operations etc. And any more high-level shorcut functions should be implemented in the map or set wrappers.
Every function is implemented without recursion.
The pointers, references and iterators are invalidated only by a deletion of the associated node, other modifications like balancing and assigments, etc. does not invalidate them.
There are two types TKey and TItem, it is this way to make the class more general and so that it can represent both sets and maps. The key type is the raw type that is used to query and compare nodes, the item type is the internal type stored in nodes, and it can be indentical to the key type.
The node allocator is derived from the item allocator TAlloc.
- Template Parameters
-
| TKey | The key type. |
| TItem | The item type, usually same as the TKey or std::pair<TKey, TValue> for some TValue. |
| TKeyComp | TKeyComp must allow comparisons between all of: two keys; two items; one key and one item; one item and one key. The comparisons must be all noexcept. |
| TAlloc | The item allocator type. |
template<class TKey , class TItem , class TKeyComp , class TAlloc >
template<class TInsertCallback >
Inserts an item to the tree.
This function functions as an all-in-one solution to the standard emplace/insert/assign methods. It takes in a key and two callback functions. Then it tries to find the key, when it succeeds, it does nothing.
When the key is not present then the new item is directly constructed from the result of insert_callback, the result is forwarded into the nodes constructor.
- Template Parameters
-
| TInsertCallback | The callback to call when constructing a new node. It should not have any parameters. It can return either an rvalue reference or lvalue reference. |
- Note
- Time Complexity: O(log n);
-
Space Complexity: O(1)
-
Strong exception guarantee.
template<class TKey , class TItem , class TKeyComp , class TAlloc >
template<class TInsertCallback , class TAssignCallback >
Inserts an item to the tree.
This function functions as an all-in-one solution to the standard emplace/insert/assign methods. It takes in a key and two callback functions. Then it tries to find the key, when it succeeds, it calls the assign_callback on the found nodes item field, so it must take in an lvalue reference to the item type an inside it you can decide whether to change the value or keep the value.
When the key is not present then the new item is directly constructed from the result of insert_callback, the result is forwarded into the nodes constructor.
- Template Parameters
-
| TAssignCallback | The callback to call when assigning a new value to an existing item field, it shall be of this signature void(item_type &). |
| TInsertCallback | The callback to call when constructing a new node. It should not have any parameters. It can return either an rvalue reference or lvalue reference. |
- Note
- Time Complexity: O(log n);
-
Space Complexity: O(1)
-
Strong exception guarantee.
template<class TKey , class TItem , class TKeyComp , class TAlloc >
Returns the dot representation of the tree.
Safe to call for every key/item type, automatically tries to convert the nodes to their string representation in the most readable way. If it fails to convert the key to string it uses their unique pointers as labels, because this function is meant to be called during debugging from the debugger, it is sufficient to display the correct structure and map it to the debugging info.
If the print_invis flag is set to true even the nullptr children will be rendered although they will be set to be invisible. It is so that you can more easily tell whether the node is greater than its child or the other way in case it has just one in some types of renders.
- Parameters
-
| print_invis | Toggles nulltpr rendering. |
- Returns
- The dot language representation of the tree.