|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Heavy-Light Decomposition over a rooted tree represented as an Aleph graph. More...
#include <Tree_Decomposition.H>
Public Types | |
| using | Node = typename GT::Node |
| using | Range = tree_decomposition_detail::Id_Range |
Public Member Functions | |
| Gen_Heavy_Light_Decomposition (const GT &g, Node *root, SA sa=SA()) | |
| Construct using an explicit root node. | |
| Gen_Heavy_Light_Decomposition (const GT &g, SA sa=SA()) | |
| Construct using the first graph node as root. | |
| size_t | size () const noexcept |
| bool | is_empty () const noexcept |
| Node * | root () const noexcept |
| size_t | root_id () const noexcept |
| Node * | node_of (const size_t id) const |
| size_t | id_of (const Node *node) const |
| size_t | parent_id (const size_t id) const |
| Node * | parent_of (const Node *node) const |
| size_t | depth_of_id (const size_t id) const |
| size_t | depth_of (const Node *node) const |
| size_t | subtree_size_of_id (const size_t id) const |
| size_t | subtree_size_of (const Node *node) const |
| size_t | heavy_child_id (const size_t id) const |
| Node * | heavy_child (const Node *node) const |
| size_t | head_id (const size_t id) const |
| Node * | head_of (const Node *node) const |
| size_t | position_of_id (const size_t id) const |
| size_t | position_of (const Node *node) const |
| Range | subtree_range_id (const size_t id) const |
| Base-array range of a full subtree (inclusive endpoints). | |
| Range | subtree_range (const Node *node) const |
| Base-array range of a full subtree (inclusive endpoints). | |
| bool | is_ancestor_id (const size_t u, const size_t v) const |
True iff u is ancestor of v in the rooted tree. | |
| bool | is_ancestor (const Node *u, const Node *v) const |
True iff u is ancestor of v in the rooted tree. | |
| size_t | lca_id (size_t u, size_t v) const |
| Lowest common ancestor in O(log n). | |
| Node * | lca (const Node *u, const Node *v) const |
| Lowest common ancestor in O(log n). | |
| size_t | distance_id (const size_t u, const size_t v) const |
| Distance (number of edges) between two node IDs. | |
| size_t | distance (const Node *u, const Node *v) const |
| Distance (number of edges) between two nodes. | |
| template<class F > | |
| void | for_each_path_segment_id (size_t u, size_t v, F &&visit) const |
Enumerate path segments from u to v in path order. | |
| template<class F > | |
| void | for_each_path_segment (const Node *u, const Node *v, F &&visit) const |
Enumerate path segments from u to v in path order. | |
| template<class F > | |
| void | for_each_path_segment_undirected_id (const size_t u, const size_t v, F &&visit) const |
| Enumerate path segments ignoring direction. | |
Private Types | |
| using | Topology = tree_decomposition_detail::Rooted_Tree_Topology< GT, SA > |
Private Member Functions | |
| void | ensure_not_empty (const char *where) const |
| void | build_decomposition () |
Private Attributes | |
| Topology | topology_ |
| Array< size_t > | parent_ |
| Array< size_t > | depth_ |
| Array< size_t > | subtree_size_ |
| Array< size_t > | heavy_ |
| Array< size_t > | head_ |
| Array< size_t > | pos_ |
| Array< size_t > | inv_pos_ |
Static Private Attributes | |
| static constexpr size_t | NONE = Topology::NONE |
Heavy-Light Decomposition over a rooted tree represented as an Aleph graph.
HLD decomposes each root-to-leaf path into heavy and light edges so that any path between two nodes can be split into O(log n) contiguous segments over a base array.
Build complexity: O(n) Path decomposition complexity: O(log n) segments
| GT | Graph type. |
| SA | Arc filter type. |
Definition at line 394 of file Tree_Decomposition.H.
| using Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::Node = typename GT::Node |
Definition at line 397 of file Tree_Decomposition.H.
| using Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::Range = tree_decomposition_detail::Id_Range |
Definition at line 398 of file Tree_Decomposition.H.
|
private |
Definition at line 401 of file Tree_Decomposition.H.
|
inline |
Construct using an explicit root node.
| [in] | g | Graph containing the rooted tree. |
| [in] | root | Root node pointer. |
| [in] | sa | Arc filter. |
Definition at line 552 of file Tree_Decomposition.H.
|
inline |
Construct using the first graph node as root.
| [in] | g | Graph containing the rooted tree. |
| [in] | sa | Arc filter. |
Definition at line 563 of file Tree_Decomposition.H.
|
inlineprivate |
Definition at line 419 of file Tree_Decomposition.H.
References Aleph::tree_decomposition_detail::Rooted_Tree_Topology< GT, SA >::adjacency(), ah_domain_error_if, Aleph::and, Aleph::Array< T >::append(), Aleph::blossom_maximum_cardinality_matching(), Aleph::Array< T >::create(), Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::depth_, Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::head_, Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::heavy_, Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::inv_pos_, Aleph::DynListStack< T >::is_empty(), Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::NONE, Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::parent_, Aleph::DynListStack< T >::pop(), Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::pos_, Aleph::DynListStack< T >::push(), Aleph::Array< T >::reserve(), Aleph::tree_decomposition_detail::Rooted_Tree_Topology< GT, SA >::root_id(), Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::root_id(), Aleph::Array< T >::size(), Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::size(), Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::subtree_size_, Aleph::DynListStack< T >::top(), and Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::topology_.
|
inline |
Definition at line 603 of file Tree_Decomposition.H.
|
inline |
Definition at line 597 of file Tree_Decomposition.H.
|
inline |
Distance (number of edges) between two nodes.
Definition at line 712 of file Tree_Decomposition.H.
|
inline |
Distance (number of edges) between two node IDs.
Definition at line 705 of file Tree_Decomposition.H.
|
inlineprivate |
Definition at line 414 of file Tree_Decomposition.H.
References ah_domain_error_if, Aleph::blossom_maximum_cardinality_matching(), and Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::is_empty().
|
inline |
Enumerate path segments from u to v in path order.
Definition at line 762 of file Tree_Decomposition.H.
References Aleph::blossom_maximum_cardinality_matching().
|
inline |
Enumerate path segments from u to v in path order.
The callback receives (l, r, reversed) where [l, r] is a contiguous segment in the HLD base array, and:
reversed == true means the path traverses that segment as r..lreversed == false means the path traverses that segment as l..rThis is useful for non-commutative path folds where segment direction matters.
Definition at line 728 of file Tree_Decomposition.H.
References Aleph::blossom_maximum_cardinality_matching().
|
inline |
Enumerate path segments ignoring direction.
Useful when the query operation is commutative.
Definition at line 772 of file Tree_Decomposition.H.
References Aleph::blossom_maximum_cardinality_matching(), l, and r.
|
inline |
Definition at line 631 of file Tree_Decomposition.H.
|
inline |
Definition at line 637 of file Tree_Decomposition.H.
|
inline |
Definition at line 625 of file Tree_Decomposition.H.
References Aleph::blossom_maximum_cardinality_matching().
|
inline |
Definition at line 619 of file Tree_Decomposition.H.
|
inline |
Definition at line 580 of file Tree_Decomposition.H.
|
inline |
True iff u is ancestor of v in the rooted tree.
Definition at line 677 of file Tree_Decomposition.H.
|
inline |
True iff u is ancestor of v in the rooted tree.
Definition at line 669 of file Tree_Decomposition.H.
References Aleph::and, Aleph::blossom_maximum_cardinality_matching(), and r.
|
inlinenoexcept |
Definition at line 570 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::ensure_not_empty().
|
inline |
Lowest common ancestor in O(log n).
Definition at line 699 of file Tree_Decomposition.H.
|
inline |
Lowest common ancestor in O(log n).
Definition at line 683 of file Tree_Decomposition.H.
|
inline |
Definition at line 575 of file Tree_Decomposition.H.
|
inline |
Definition at line 585 of file Tree_Decomposition.H.
|
inline |
Definition at line 591 of file Tree_Decomposition.H.
|
inline |
Definition at line 648 of file Tree_Decomposition.H.
|
inline |
Definition at line 642 of file Tree_Decomposition.H.
|
inlinenoexcept |
Definition at line 572 of file Tree_Decomposition.H.
|
inlinenoexcept |
Definition at line 573 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::build_decomposition().
|
inlinenoexcept |
Definition at line 569 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::build_decomposition().
|
inline |
Base-array range of a full subtree (inclusive endpoints).
Definition at line 663 of file Tree_Decomposition.H.
|
inline |
Base-array range of a full subtree (inclusive endpoints).
Definition at line 654 of file Tree_Decomposition.H.
|
inline |
Definition at line 614 of file Tree_Decomposition.H.
|
inline |
Definition at line 608 of file Tree_Decomposition.H.
|
private |
Definition at line 407 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::build_decomposition().
|
private |
Definition at line 410 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::build_decomposition().
|
private |
Definition at line 409 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::build_decomposition().
|
private |
Definition at line 412 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::build_decomposition().
|
staticconstexprprivate |
Definition at line 402 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::build_decomposition().
|
private |
Definition at line 406 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::build_decomposition().
|
private |
Definition at line 411 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::build_decomposition().
|
private |
Definition at line 408 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::build_decomposition().
|
private |
Definition at line 404 of file Tree_Decomposition.H.
Referenced by Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::build_decomposition().