|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Segment-tree-powered path/subtree queries over an HLD layout. More...
#include <Tree_Decomposition.H>
Public Types | |
| using | Node = typename GT::Node |
Public Member Functions | |
| Gen_HLD_Path_Query (const GT &g, Node *root, const T &identity, Op op=Op(), SA sa=SA()) | |
Construct from graph/root using node->get_info() as initial values. | |
| Gen_HLD_Path_Query (const GT &g, const T &identity, Op op=Op(), SA sa=SA()) | |
Construct from graph (first node as root) using node->get_info(). | |
| template<class Getter > requires std::invocable<Getter, Node *> | |
| and std::convertible_to< std::invoke_result_t< Getter, Node * >, T > | Gen_HLD_Path_Query (const GT &g, Node *root, Getter getter, const T &identity, Op op=Op(), SA sa=SA()) |
| Construct with custom node-to-value getter. | |
| template<class Getter > requires std::invocable<Getter, Node *> | |
| and std::convertible_to< std::invoke_result_t< Getter, Node * >, T > | Gen_HLD_Path_Query (const GT &g, Getter getter, const T &identity, Op op=Op(), SA sa=SA()) |
| Construct with custom getter and implicit root (first node). | |
| Gen_HLD_Path_Query (const Gen_HLD_Path_Query &other)=default | |
| Copy the decomposition and the values of another engine. | |
| Gen_HLD_Path_Query (Gen_HLD_Path_Query &&other)=default | |
| Take the decomposition and the values of another engine, which is left empty. | |
| Gen_HLD_Path_Query & | operator= (const Gen_HLD_Path_Query &other)=default |
| Copy the decomposition and the values of another engine. | |
| Gen_HLD_Path_Query & | operator= (Gen_HLD_Path_Query &&other) noexcept(noexcept(swap(other))) |
| Exchange this engine with another, which is left with the previous tree and values of this one. | |
| void | swap (Gen_HLD_Path_Query &other) noexcept(std::is_nothrow_swappable_v< T > and std::is_nothrow_swappable_v< Op > and std::is_nothrow_move_assignable_v< Gen_Heavy_Light_Decomposition< GT, SA > >) |
| Exchange in O(1) this engine and another. | |
| const Gen_Heavy_Light_Decomposition< GT, SA > & | decomposition () const noexcept |
| size_t | size () const noexcept |
| bool | is_empty () const noexcept |
| T | query_path_id (const size_t u, const size_t v) const |
| Path query between two node IDs in O(log^2 n). | |
| T | query_path (const Node *u, const Node *v) const |
| Path query between two nodes in O(log^2 n). | |
| T | query_subtree_id (const size_t id) const |
| Subtree query for node ID in O(log n). | |
| T | query_subtree (const Node *node) const |
| Subtree query for node in O(log n). | |
| void | update_node_id (const size_t id, const T &delta) |
Point update: a[id] = Op(a[id], delta). | |
| void | update_node (const Node *node, const T &delta) |
Point update: a[node] = Op(a[node], delta). | |
| void | set_node_id (const size_t id, const T &value) |
Point assignment: a[id] = value. | |
| void | set_node (const Node *node, const T &value) |
Point assignment: a[node] = value. | |
| T | get_node_id (const size_t id) const |
| Return current value at node ID. | |
| T | get_node (const Node *node) const |
| Return current value at node. | |
Private Member Functions | |
| void | ensure_not_empty (const char *where) const |
| void | swap_all_or_none (Gen_HLD_Path_Query &other) |
Static Private Member Functions | |
| template<class Getter > requires std::invocable<Getter, Node *> | |
| and static std::convertible_to< std::invoke_result_t< Getter, Node * >, T > Array< T > | build_base_array (const Gen_Heavy_Light_Decomposition< GT, SA > &hld, Getter getter) |
| static Array< T > | build_base_from_node_info (const Gen_Heavy_Light_Decomposition< GT, SA > &hld) |
Private Attributes | |
| Gen_Heavy_Light_Decomposition< GT, SA > | hld_ |
| Gen_Segment_Tree< T, Op > | segment_tree_ |
| T | identity_ |
| Op | op_ |
Segment-tree-powered path/subtree queries over an HLD layout.
This class combines Gen_Heavy_Light_Decomposition with Gen_Segment_Tree for convenient dynamic queries.
Supported operations:
query_path(u, v)query_subtree(u)update_node(u, delta)set_node(u, value)get_node(u)query_path() combines segment answers with Op and therefore assumes this fold is valid for your query semantics. For non-commutative path queries, use for_each_path_segment_id() from Gen_Heavy_Light_Decomposition and handle direction explicitly.| GT | Graph type. |
| T | Segment value type. |
| Op | Associative operation. |
| SA | Arc filter type. |
Definition at line 879 of file Tree_Decomposition.H.
| using Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::Node = typename GT::Node |
Definition at line 882 of file Tree_Decomposition.H.
|
inline |
Construct from graph/root using node->get_info() as initial values.
Definition at line 926 of file Tree_Decomposition.H.
|
inline |
Construct from graph (first node as root) using node->get_info().
Definition at line 940 of file Tree_Decomposition.H.
|
inline |
Construct with custom node-to-value getter.
Definition at line 956 of file Tree_Decomposition.H.
|
inline |
Construct with custom getter and implicit root (first node).
Definition at line 974 of file Tree_Decomposition.H.
|
default |
Copy the decomposition and the values of another engine.
| [in] | other | engine to copy. |
|
default |
Take the decomposition and the values of another engine, which is left empty.
The decomposition of the moved-from engine is empty, so that the engine never queries the segment tree that the move leaves to it.
| [in,out] | other | engine to move from. |
|
inlinestaticprivate |
Definition at line 898 of file Tree_Decomposition.H.
References Aleph::Array< T >::create(), Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::node_of(), Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::position_of_id(), and Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::size().
Referenced by Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::build_base_from_node_info().
|
inlinestaticprivate |
Definition at line 915 of file Tree_Decomposition.H.
References Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::build_base_array().
|
inlinenoexcept |
Definition at line 1091 of file Tree_Decomposition.H.
References Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::hld_.
Referenced by Moved_From_Case< HLD_Path_Query< Graph, int, Aleph::plus< int > > >::is_empty(), main(), TYPED_TEST(), TYPED_TEST(), and Moved_From_Case< HLD_Path_Query< Graph, int, Aleph::plus< int > > >::use().
|
inlineprivate |
Definition at line 890 of file Tree_Decomposition.H.
References ah_domain_error_if, and Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::is_empty().
Referenced by Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::get_node_id(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::query_path_id(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::query_subtree_id(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::set_node_id(), and Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::update_node_id().
|
inline |
Return current value at node.
Definition at line 1169 of file Tree_Decomposition.H.
References Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::get_node_id(), and Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::hld_.
|
inline |
Return current value at node ID.
Definition at line 1162 of file Tree_Decomposition.H.
References Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::ensure_not_empty(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::hld_, and Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::segment_tree_.
Referenced by Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::get_node(), TYPED_TEST(), and Moved_From_Case< HLD_Path_Query< Graph, int, Aleph::plus< int > > >::use().
|
inlinenoexcept |
Definition at line 1097 of file Tree_Decomposition.H.
References Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::hld_.
Referenced by Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::ensure_not_empty(), Moved_From_Case< HLD_Path_Query< Graph, int, Aleph::plus< int > > >::is_empty(), TYPED_TEST(), TYPED_TEST(), and Moved_From_Case< HLD_Path_Query< Graph, int, Aleph::plus< int > > >::use().
|
default |
Copy the decomposition and the values of another engine.
| [in] | other | engine to copy. |
|
inlinenoexcept |
Exchange this engine with another, which is left with the previous tree and values of this one.
The implicit assignment left the segment tree to its own move assignment, which exchanged its array but copied its size, and copied the identity: the moved-from engine then queried the tree that it received with the size of its own.
| [in,out] | other | engine to move from. |
Definition at line 1019 of file Tree_Decomposition.H.
References Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap().
|
inline |
Path query between two nodes in O(log^2 n).
Definition at line 1116 of file Tree_Decomposition.H.
References Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::hld_, and Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::query_path_id().
Referenced by main(), TYPED_TEST(), TYPED_TEST(), TYPED_TEST(), TYPED_TEST(), and TYPED_TEST().
|
inline |
Path query between two node IDs in O(log^2 n).
Definition at line 1100 of file Tree_Decomposition.H.
References Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::ensure_not_empty(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::hld_, Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::identity_, l, Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::op_, r, and Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::segment_tree_.
Referenced by main(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::query_path(), TYPED_TEST(), TYPED_TEST(), and Moved_From_Case< HLD_Path_Query< Graph, int, Aleph::plus< int > > >::use().
|
inline |
Subtree query for node in O(log n).
Definition at line 1130 of file Tree_Decomposition.H.
References Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::hld_, and Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::query_subtree_id().
Referenced by TYPED_TEST(), TYPED_TEST(), and TYPED_TEST().
|
inline |
Subtree query for node ID in O(log n).
Definition at line 1122 of file Tree_Decomposition.H.
References Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::ensure_not_empty(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::hld_, Aleph::range(), and Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::segment_tree_.
Referenced by main(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::query_subtree(), TYPED_TEST(), and Moved_From_Case< HLD_Path_Query< Graph, int, Aleph::plus< int > > >::use().
|
inline |
Point assignment: a[node] = value.
Definition at line 1156 of file Tree_Decomposition.H.
References Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::hld_, Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::set_node_id(), and value.
Referenced by TYPED_TEST(), TYPED_TEST(), and TYPED_TEST().
|
inline |
Point assignment: a[id] = value.
Definition at line 1149 of file Tree_Decomposition.H.
References Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::ensure_not_empty(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::hld_, Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::segment_tree_, and value.
Referenced by main(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::set_node(), TYPED_TEST(), and TYPED_TEST().
|
inlinenoexcept |
Definition at line 1096 of file Tree_Decomposition.H.
References Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::hld_.
Referenced by Moved_From_Case< HLD_Path_Query< Graph, int, Aleph::plus< int > > >::is_empty(), TYPED_TEST(), and Moved_From_Case< HLD_Path_Query< Graph, int, Aleph::plus< int > > >::use().
|
inlinenoexcept |
Exchange in O(1) this engine and another.
| [in,out] | other | engine to exchange with. |
| what | swapping the values, the operations or the filters throws. The values and the operations are exchanged first, and then the segment trees and the decompositions, each all or none: if a swap throws, those before it are exchanged back, and both engines are left as they were, if the swap that threw left its arguments as they were. If a swap that puts one back throws too, both engines can only be destroyed or assigned. |
Definition at line 1037 of file Tree_Decomposition.H.
References Aleph::and, Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::hld_, Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::identity_, Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::op_, Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::segment_tree_, Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap(), and Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap_all_or_none().
Referenced by Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::operator=(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap(), and Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap_all_or_none().
|
inlineprivate |
Definition at line 1064 of file Tree_Decomposition.H.
References Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::hld_, Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::identity_, Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::op_, Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::segment_tree_, and Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap().
Referenced by Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap().
|
inline |
Point update: a[node] = Op(a[node], delta).
Definition at line 1143 of file Tree_Decomposition.H.
References Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::hld_, and Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::update_node_id().
Referenced by TYPED_TEST(), TYPED_TEST(), TYPED_TEST(), TYPED_TEST(), and TYPED_TEST().
|
inline |
Point update: a[id] = Op(a[id], delta).
Definition at line 1136 of file Tree_Decomposition.H.
References Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::ensure_not_empty(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::hld_, and Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::segment_tree_.
Referenced by main(), TYPED_TEST(), TYPED_TEST(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::update_node(), and Moved_From_Case< HLD_Path_Query< Graph, int, Aleph::plus< int > > >::use().
|
private |
Definition at line 885 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::decomposition(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::get_node(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::get_node_id(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::is_empty(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::query_path(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::query_path_id(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::query_subtree(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::query_subtree_id(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::set_node(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::set_node_id(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::size(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap_all_or_none(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::update_node(), and Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::update_node_id().
|
private |
Definition at line 887 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::query_path_id(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap(), and Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap_all_or_none().
|
private |
Definition at line 888 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::query_path_id(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap(), and Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap_all_or_none().
|
private |
Definition at line 886 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::get_node_id(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::query_path_id(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::query_subtree_id(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::set_node_id(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::swap_all_or_none(), and Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::update_node_id().