LAL: Linear Arrangement Library 23.01.00
A library focused on algorithms on linear arrangements of graphs.
|
Simple class that implements an AVL tree. More...
#include <avl.hpp>
Classes | |
struct | frequencies |
Frequency of a value in the tree v. More... | |
struct | tree_node |
Node of the tree. More... | |
Public Member Functions | |
~AVL () noexcept | |
Destructor. | |
void | clear () noexcept |
Empties the tree. More... | |
std::pair< const T &, frequencies > | get_largest_value () const noexcept |
Finds the largest value. More... | |
template<bool use_counter> | |
frequencies | remove_largest () noexcept |
Remove an element from the tree. More... | |
template<bool use_counter> | |
frequencies | remove_smallest () noexcept |
Remove an element from the tree. More... | |
std::pair< const T &, frequencies > | get_smallest_value () const noexcept |
Find the largest value. More... | |
frequencies | element_frequency (const T &v) const noexcept |
Number of occurrences associated to a given value. More... | |
template<typename U > | |
frequencies | insert (U &&v) noexcept |
Insert a new value v into the tree. More... | |
template<bool use_counter> | |
frequencies | remove (const T &v) noexcept |
Remove an element from the tree. More... | |
template<typename U > | |
void | join_sorted_all_greater (U &&v) noexcept |
Add to the tree the elements in the vector v. More... | |
std::size_t | num_nodes () const noexcept |
Size of the tree. More... | |
std::size_t | total_elements () const noexcept |
Total number of elements inserted. More... | |
Private Member Functions | |
void | free_node (tree_node *n) const noexcept |
Deallocates the memory of node n. | |
tree_node * | right_rotation (tree_node *n) const noexcept |
Performs a right-rotation at node n. More... | |
tree_node * | left_rotation (tree_node *n) const noexcept |
Performs a left-rotation at node n. More... | |
tree_node * | left_left_case (tree_node *n) const noexcept |
Left-left imbalance case. More... | |
tree_node * | left_right_case (tree_node *n) const noexcept |
Left-right imbalance case. More... | |
tree_node * | right_right_case (tree_node *n) const noexcept |
Right-right imbalance case. More... | |
tree_node * | right_left_case (tree_node *n) const noexcept |
Right-left imbalance case. More... | |
tree_node * | balance (tree_node *n) const noexcept |
Balance a node of the AVL tree. More... | |
template<typename U > | |
tree_node * | insert (tree_node *p, tree_node *n, U &&x, frequencies &freqs) const noexcept |
Insert element 'x' to the tree. More... | |
template<bool use_counter_to_remove, bool move_in_leftmost> | |
bool | delete_after_move (tree_node *n, tree_node *k, frequencies &freqs) const noexcept |
Moves the contents of n to k, when appropriate. More... | |
template<bool use_counter_to_remove> | |
tree_node * | remove_leftmost (tree_node *n, tree_node *k, frequencies &freqs) const noexcept |
Remove the leftmost node in tree rooted at n. More... | |
template<bool use_counter_to_remove> | |
tree_node * | remove_rightmost (tree_node *n, tree_node *k, frequencies &freqs) const noexcept |
Remove the rightmost node in tree rooted at n. More... | |
template<bool use_counter_to_remove> | |
tree_node * | remove (tree_node *n, const T &x, frequencies &freqs) const noexcept |
Remove an element from the tree. More... | |
tree_node * | join_taller (tree_node *T1, tree_node *T2) const noexcept |
Join two AVL trees. More... | |
tree_node * | join_shorter (tree_node *T1, tree_node *T2) const noexcept |
Join two AVL trees. More... | |
template<typename U > | |
tree_node * | _make_tree (U &&v, std::size_t l, std::size_t r, tree_node *p, char s) const noexcept |
Make an AVL tree from the elements in v. More... | |
Private Attributes | |
tree_node * | m_root = nullptr |
Root of this AVL tree. | |
Simple class that implements an AVL tree.
This class can store repeated elements. However, it will never contain two nodes with the same key. Every element is inserted with a total number of occurrences associated to it. So an element inserted three times (and never deleted) will be in the tree in a single node and its number of occurrences will be 3. Each time an element is removed, its number of occurrences decreases by 1.
Deletion of nodes depends on the template parameter of functions remove. Read their documentation for further details.
|
inlineprivatenoexcept |
Make an AVL tree from the elements in v.
This function performs a recursive binary search over v. The limits of this search are l and r. At each call, this function creates a tree_node with the value in the midpoint between l and r.
v | Vector sorted non-decreasingly. |
l | Left-limit of the binary search- |
r | Right-limit of the binary search. |
p | Parent of the new node to be created. |
s | Side of the node to create with respect to the parent. |
|
inlineprivatenoexcept |
Balance a node of the AVL tree.
Uses the functions left_left_case, left_right_case, right_right_case, right_left_case.
n | Node to balance |
|
inlinenoexcept |
Empties the tree.
Clears all the memory used by this tree. References to its elements are invalidated.
|
inlineprivatenoexcept |
Moves the contents of n to k, when appropriate.
use_counter_to_remove | If true then this node is to be removed only if the counter has reached 0. If false, the node will be removed regardless of the value. |
move_in_leftmost | Was this function called from remove_leftmost? |
n | Node of the tree. | |
[out] | k | Copy of the leftmost node. |
[out] | freqs | The frequencies associated to the leftmost node. |
|
inlinenoexcept |
Number of occurrences associated to a given value.
v | Value to find. |
|
inlinenoexcept |
Finds the largest value.
|
inlinenoexcept |
Find the largest value.
|
inlineprivatenoexcept |
Insert element 'x' to the tree.
p | Parent of node n | |
n | Node to which the element 'x' is to be assigned. | |
x | Element to be added. | |
[out] | freqs | Frequencies associated to the value x. |
|
inlinenoexcept |
Insert a new value v into the tree.
v | New value. |
|
inlineprivatenoexcept |
Join two AVL trees.
T1 | Shorter tree. |
T2 | Taller tree. |
|
inlinenoexcept |
Add to the tree the elements in the vector v.
The element passed as parameter must be a std::vector<T>.
v | A sorted collection of unique elements. |
|
inlineprivatenoexcept |
Join two AVL trees.
T1 | Taller tree. |
T2 | Shorter tree. |
|
inlineprivatenoexcept |
Left-left imbalance case.
n | Node. |
|
inlineprivatenoexcept |
Left-right imbalance case.
n | Node. |
|
inlineprivatenoexcept |
Performs a left-rotation at node n.
n | Node. |
|
inlinenoexcept |
Size of the tree.
|
inlinenoexcept |
Remove an element from the tree.
use_counter | If true then a node will be removed only if its counter has reached 0. If false then the node will be removed regardless of the value of the counter. |
v | The element to be removed. |
|
inlineprivatenoexcept |
Remove an element from the tree.
use_counter_to_remove | If true, the node is deleted only when the node counter reaches 0. If false, the node is always deleted. |
n | Root node. | |
x | Element to be removed. | |
[out] | freqs | Frequencies associated to the value x. |
|
inlinenoexcept |
Remove an element from the tree.
use_counter | If true then a node will be removed only if its counter has reached 0. If false then the node will be removed regardless of the value of the counter. |
|
inlineprivatenoexcept |
Remove the leftmost node in tree rooted at n.
use_counter_to_remove | If true then this node is to be removed only if the counter has reached 0. If false, the node will be removed regardless of the value. |
n | Node of the tree. | |
[out] | k | Copy of the leftmost node. |
[out] | freqs | The frequencies associated to the leftmost node. |
|
inlineprivatenoexcept |
Remove the rightmost node in tree rooted at n.
use_counter_to_remove | If true then this node is to be removed only if the counter has reached 0. If false, the node will be removed regardless of the value. |
n | Node of the tree. | |
[out] | k | Copy of the rightmost node. |
[out] | freqs | The frequencies associated to the rightmost node. |
|
inlinenoexcept |
Remove an element from the tree.
use_counter | If true then a node will be removed only if its counter has reached 0. If false then the node will be removed regardless of the value of the counter. |
|
inlineprivatenoexcept |
Right-left imbalance case.
n | Node. |
|
inlineprivatenoexcept |
Right-right imbalance case.
n | Node. |
|
inlineprivatenoexcept |
Performs a right-rotation at node n.
n | Node. |
|
inlinenoexcept |
Total number of elements inserted.