|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Offline subtree and path queries on N-ary trees (Tree_Node). More...
#include <tpl_mo_on_trees.H>
Public Types | |
| using | Node = Tree_Node< T > |
| using | answer_type = typename Policy::answer_type |
Public Member Functions | |
| Gen_Mo_On_Tree_Node (Node *root, Policy p=Policy()) | |
| Construct a Mo's algorithm query engine for N-ary trees. | |
| Gen_Mo_On_Tree_Node (const Gen_Mo_On_Tree_Node &other)=default | |
| Copy the tables of another engine. | |
| Gen_Mo_On_Tree_Node (Gen_Mo_On_Tree_Node &&other) noexcept(std::is_nothrow_move_constructible_v< Policy >) | |
| Take the tables of another engine, which is left empty. | |
| Gen_Mo_On_Tree_Node & | operator= (const Gen_Mo_On_Tree_Node &other)=default |
| Copy the tables of another engine. | |
| Gen_Mo_On_Tree_Node & | operator= (Gen_Mo_On_Tree_Node &&other) noexcept(noexcept(swap(other))) |
| Exchange this engine with another, which is left with the previous tree of this one. | |
| void | swap (Gen_Mo_On_Tree_Node &other) noexcept(std::is_nothrow_swappable_v< Policy >) |
| Exchange in O(1) this engine and another. | |
| size_t | size () const noexcept |
| Number of nodes in the tree. | |
| bool | is_empty () const noexcept |
| True if the tree is empty. | |
| Array< answer_type > | subtree_solve (const Array< Node * > &query_roots) const |
| Answer subtree queries on the N-ary tree. | |
| Array< answer_type > | subtree_solve (std::initializer_list< Node * > il) const |
| Solve subtree queries (initializer-list overload). | |
| Array< answer_type > | path_solve (const Array< std::pair< Node *, Node * > > &query_pairs) const |
| Answer path queries on the N-ary tree. | |
| Array< answer_type > | path_solve (std::initializer_list< std::pair< Node *, Node * > > il) const |
| Solve path queries (initializer-list overload). | |
Private Member Functions | |
| void | build () |
| size_t | lca (size_t u, size_t v) const |
| Array< answer_type > | mo_sweep (const Array< T > &data, Array< Mo_Query > queries, size_t nn) const |
Private Attributes | |
| Node * | root_ |
| Policy | pol_ |
| size_t | n_ = 0 |
| Array< Node * > | id_to_node_ |
| MapOLhash< Node *, size_t > | node_to_id_ |
| Array< T > | node_values_ |
| Array< size_t > | tin_ |
| Array< size_t > | tout_ |
| Array< T > | flat_sub_ |
| Array< size_t > | first_ |
| Array< size_t > | last_ |
| Array< size_t > | flat_node_ |
| size_t | log_n_ = 0 |
| Array< size_t > | depth_ |
| Array< size_t > | parent_ |
| Array< size_t > | up_ |
Static Private Attributes | |
| static constexpr size_t | NONE = ~size_t(0) |
Offline subtree and path queries on N-ary trees (Tree_Node).
Same algorithm as Gen_Mo_On_Trees but works directly with the first-child / next-sibling representation of Tree_Node<T>. The tree is traversed via get_left_child() / get_right_sibling() instead of graph adjacency iterators.
| T | Value type stored in each Tree_Node. |
| Policy | A type satisfying MoPolicy<Policy, T>. |
Definition at line 737 of file tpl_mo_on_trees.H.
| using Aleph::Gen_Mo_On_Tree_Node< T, Policy >::answer_type = typename Policy::answer_type |
Definition at line 741 of file tpl_mo_on_trees.H.
| using Aleph::Gen_Mo_On_Tree_Node< T, Policy >::Node = Tree_Node<T> |
Definition at line 740 of file tpl_mo_on_trees.H.
|
inline |
Construct a Mo's algorithm query engine for N-ary trees.
Performs an O(N log N) preprocessing step. The tree is not modified in any way.
| root | Root of the N-ary tree (must not be null). |
| p | Policy object copied/moved into the query engine. |
| std::domain_error | If root is null or tree is inconsistent. |
| std::bad_alloc | If auxiliary arrays/tables cannot be allocated. |
Definition at line 1032 of file tpl_mo_on_trees.H.
References ah_domain_error_if, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::build(), and root().
|
default |
Copy the tables of another engine.
| [in] | other | engine to copy. |
|
inlinenoexcept |
Take the tables of another engine, which is left empty.
The implicit move took the arrays and the map but copied the number of nodes and the levels of the lifting table: the moved-from engine then reported the old size for a tree without nodes, and the source of an assignment read the lifting table that it received with the size of its own.
| [in,out] | other | engine to move from. |
Definition at line 1058 of file tpl_mo_on_trees.H.
|
inlineprivate |
Definition at line 773 of file tpl_mo_on_trees.H.
References ah_domain_error_if, Aleph::DynArray< T >::append(), Aleph::DynList< T >::append(), Aleph::Array< T >::create(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::depth_, Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::find(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::first_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::flat_node_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::flat_sub_, Aleph::DynArray< T >::get_it(), Aleph::Tree_Node< T >::get_key(), Aleph::Tree_Node< T >::get_left_child(), Aleph::Tree_Node< T >::get_parent(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::id_to_node_, Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::insert(), Aleph::DynListStack< T >::is_empty(), k, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::last_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::log_n_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::n_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::node_to_id_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::node_values_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::NONE, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::parent_, Aleph::DynListStack< T >::pop(), preorder, Aleph::DynListStack< T >::push(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::root_, Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::search(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::tin_, Aleph::DynListStack< T >::top(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::tout_, and Aleph::Gen_Mo_On_Tree_Node< T, Policy >::up_.
Referenced by Aleph::Gen_Mo_On_Tree_Node< T, Policy >::Gen_Mo_On_Tree_Node().
|
inlinenoexcept |
True if the tree is empty.
Definition at line 1128 of file tpl_mo_on_trees.H.
References Aleph::Gen_Mo_On_Tree_Node< T, Policy >::n_.
|
inlineprivate |
Definition at line 946 of file tpl_mo_on_trees.H.
References Aleph::Gen_Mo_On_Tree_Node< T, Policy >::depth_, Aleph::diff(), k, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::log_n_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::n_, and Aleph::Gen_Mo_On_Tree_Node< T, Policy >::up_.
Referenced by Aleph::Gen_Mo_On_Tree_Node< T, Policy >::path_solve().
|
inlineprivate |
Definition at line 970 of file tpl_mo_on_trees.H.
References Aleph::Array< T >::create(), Aleph::introsort(), Aleph::Mo_Query::l, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::pol_, r, Aleph::Mo_Query::r, and Aleph::Array< T >::size().
Referenced by Aleph::Gen_Mo_On_Tree_Node< T, Policy >::subtree_solve().
|
default |
Copy the tables of another engine.
| [in] | other | engine to copy. |
|
inlinenoexcept |
Exchange this engine with another, which is left with the previous tree of this one.
| [in,out] | other | engine to move from. |
Definition at line 1081 of file tpl_mo_on_trees.H.
References Aleph::Gen_Mo_On_Tree_Node< T, Policy >::swap().
|
inline |
Answer path queries on the N-ary tree.
| query_pairs | Array of (u, v) node-pointer pairs. |
| std::domain_error | If any query endpoint is not in the tree. |
| Any | exception thrown by Policy::init, Policy::add, Policy::remove, or Policy::answer. |
Definition at line 1196 of file tpl_mo_on_trees.H.
References ah_domain_error_if, Aleph::Array< T >::create(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::first_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::flat_node_, Aleph::introsort(), l, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::last_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::lca(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::n_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::node_to_id_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::node_values_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::NONE, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::pol_, r, and Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::search().
Referenced by filesystem_inodes(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::path_solve(), TEST(), TEST(), TEST(), and TEST().
|
inline |
Solve path queries (initializer-list overload).
| il | Initializer list of (u, v) node-pointer pairs. |
| std::domain_error | If any query endpoint is not in the tree. |
| Any | exception propagated from path_solve(Array<pair<...>>) and policy callbacks. |
Definition at line 1318 of file tpl_mo_on_trees.H.
References Aleph::Gen_Mo_On_Tree_Node< T, Policy >::path_solve().
|
inlinenoexcept |
Number of nodes in the tree.
Definition at line 1125 of file tpl_mo_on_trees.H.
References Aleph::Gen_Mo_On_Tree_Node< T, Policy >::n_.
|
inline |
Answer subtree queries on the N-ary tree.
| query_roots | Array of subtree root nodes. |
| std::domain_error | If any query root is not in the tree. |
| Any | exception thrown by Policy::init, Policy::add, Policy::remove, or Policy::answer. |
Definition at line 1144 of file tpl_mo_on_trees.H.
References ah_domain_error_if, Aleph::Array< T >::create(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::flat_sub_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::mo_sweep(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::n_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::node_to_id_, Aleph::MapOpenHash< Key, Data, Cmp, HashTable >::search(), Aleph::Array< T >::size(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::tin_, and Aleph::Gen_Mo_On_Tree_Node< T, Policy >::tout_.
Referenced by filesystem_inodes(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::subtree_solve(), TEST(), TEST(), TEST(), TEST(), and TEST().
|
inline |
Solve subtree queries (initializer-list overload).
| il | Initializer list of subtree root nodes. |
| std::domain_error | If any query root is not in the tree. |
| Any | exception propagated from subtree_solve(Array<Node*>). |
Definition at line 1175 of file tpl_mo_on_trees.H.
References Aleph::Gen_Mo_On_Tree_Node< T, Policy >::subtree_solve().
|
inlinenoexcept |
Exchange in O(1) this engine and another.
| [in,out] | other | engine to exchange with. |
| what | swapping the policies throws. They are exchanged first, so that, if that swap throws, nothing else is exchanged, and both engines are left as they were if it left its arguments as they were. |
Definition at line 1095 of file tpl_mo_on_trees.H.
References Aleph::Gen_Mo_On_Tree_Node< T, Policy >::depth_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::first_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::flat_node_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::flat_sub_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::id_to_node_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::last_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::log_n_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::n_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::node_to_id_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::node_values_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::parent_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::pol_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::root_, Aleph::Array< T >::swap(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::swap(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::tin_, Aleph::Gen_Mo_On_Tree_Node< T, Policy >::tout_, and Aleph::Gen_Mo_On_Tree_Node< T, Policy >::up_.
Referenced by Aleph::Gen_Mo_On_Tree_Node< T, Policy >::operator=(), and Aleph::Gen_Mo_On_Tree_Node< T, Policy >::swap().
|
private |
Definition at line 767 of file tpl_mo_on_trees.H.
Referenced by Aleph::Gen_Mo_On_Tree_Node< T, Policy >::build(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::lca(), and Aleph::Gen_Mo_On_Tree_Node< T, Policy >::swap().
|
private |
Definition at line 761 of file tpl_mo_on_trees.H.
Referenced by Aleph::Gen_Mo_On_Tree_Node< T, Policy >::build(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::path_solve(), and Aleph::Gen_Mo_On_Tree_Node< T, Policy >::swap().
|
private |
Definition at line 763 of file tpl_mo_on_trees.H.
Referenced by Aleph::Gen_Mo_On_Tree_Node< T, Policy >::build(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::path_solve(), and Aleph::Gen_Mo_On_Tree_Node< T, Policy >::swap().
|
private |
Definition at line 758 of file tpl_mo_on_trees.H.
Referenced by Aleph::Gen_Mo_On_Tree_Node< T, Policy >::build(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::subtree_solve(), and Aleph::Gen_Mo_On_Tree_Node< T, Policy >::swap().
|
private |
Definition at line 751 of file tpl_mo_on_trees.H.
Referenced by Aleph::Gen_Mo_On_Tree_Node< T, Policy >::build(), and Aleph::Gen_Mo_On_Tree_Node< T, Policy >::swap().
|
private |
Definition at line 762 of file tpl_mo_on_trees.H.
Referenced by Aleph::Gen_Mo_On_Tree_Node< T, Policy >::build(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::path_solve(), and Aleph::Gen_Mo_On_Tree_Node< T, Policy >::swap().
|
private |
Definition at line 766 of file tpl_mo_on_trees.H.
Referenced by Aleph::Gen_Mo_On_Tree_Node< T, Policy >::build(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::lca(), and Aleph::Gen_Mo_On_Tree_Node< T, Policy >::swap().
|
private |
Definition at line 748 of file tpl_mo_on_trees.H.
Referenced by Aleph::Gen_Mo_On_Tree_Node< T, Policy >::build(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::is_empty(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::lca(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::path_solve(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::size(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::subtree_solve(), and Aleph::Gen_Mo_On_Tree_Node< T, Policy >::swap().
|
private |
|
private |
Definition at line 753 of file tpl_mo_on_trees.H.
Referenced by Aleph::Gen_Mo_On_Tree_Node< T, Policy >::build(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::path_solve(), and Aleph::Gen_Mo_On_Tree_Node< T, Policy >::swap().
|
staticconstexprprivate |
Definition at line 744 of file tpl_mo_on_trees.H.
Referenced by Aleph::Gen_Mo_On_Tree_Node< T, Policy >::build(), and Aleph::Gen_Mo_On_Tree_Node< T, Policy >::path_solve().
|
private |
Definition at line 768 of file tpl_mo_on_trees.H.
Referenced by Aleph::Gen_Mo_On_Tree_Node< T, Policy >::build(), and Aleph::Gen_Mo_On_Tree_Node< T, Policy >::swap().
|
mutableprivate |
Definition at line 747 of file tpl_mo_on_trees.H.
Referenced by Aleph::Gen_Mo_On_Tree_Node< T, Policy >::mo_sweep(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::path_solve(), and Aleph::Gen_Mo_On_Tree_Node< T, Policy >::swap().
|
private |
Definition at line 746 of file tpl_mo_on_trees.H.
Referenced by Aleph::Gen_Mo_On_Tree_Node< T, Policy >::build(), and Aleph::Gen_Mo_On_Tree_Node< T, Policy >::swap().
|
private |
Definition at line 756 of file tpl_mo_on_trees.H.
Referenced by Aleph::Gen_Mo_On_Tree_Node< T, Policy >::build(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::subtree_solve(), and Aleph::Gen_Mo_On_Tree_Node< T, Policy >::swap().
|
private |
Definition at line 757 of file tpl_mo_on_trees.H.
Referenced by Aleph::Gen_Mo_On_Tree_Node< T, Policy >::build(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::subtree_solve(), and Aleph::Gen_Mo_On_Tree_Node< T, Policy >::swap().
|
private |
Definition at line 769 of file tpl_mo_on_trees.H.
Referenced by Aleph::Gen_Mo_On_Tree_Node< T, Policy >::build(), Aleph::Gen_Mo_On_Tree_Node< T, Policy >::lca(), and Aleph::Gen_Mo_On_Tree_Node< T, Policy >::swap().