111# ifndef TREE_DECOMPOSITION_H
112# define TREE_DECOMPOSITION_H
120# include <type_traits>
134 namespace tree_decomposition_detail
153 template <AlephGraph GT, ArcFilter<GT> SA>
163 static constexpr size_t NONE = std::numeric_limits<size_t>::max();
183 return std::make_pair(u, v);
186 void check_id(
const size_t id,
const char *where)
const
189 << where <<
": id=" <<
id <<
" is out of range [0, " <<
n_ <<
")";
199 <<
"Rooted_Tree_Topology: root node provided but graph is empty";
211 Node *p = it.get_curr();
218 <<
"Rooted_Tree_Topology: failed to index all graph nodes";
220 if (
root_ ==
nullptr)
224 <<
"Rooted_Tree_Topology: root node does not belong to graph";
236 for (
size_t i = 0; i <
n_; ++i)
240 size_t edge_count = 0;
244 Arc *a = it.get_curr_ne();
252 <<
"Rooted_Tree_Topology: arc endpoint is not indexed";
254 const size_t u = src_item->second;
255 const size_t v = tgt_item->second;
258 <<
"Rooted_Tree_Topology: self-loop detected in filtered graph";
262 <<
"Rooted_Tree_Topology: parallel/duplicate edge detected in filtered graph";
264 unique_edges.
insert(key, 1);
269 <<
"Rooted_Tree_Topology: filtered graph is not a tree (expected "
270 << (
n_ - 1) <<
" edges, got " << edge_count <<
")";
273 it.has_curr(); it.next_ne())
275 const auto & [fst, snd] = it.get_curr();
278 const size_t u = fst.first;
279 const size_t v = fst.second;
291 for (
size_t i = 0; i <
n_; ++i)
303 size_t visited_count = 1;
308 auto & fr = stack.
top();
310 if (fr.next_child ==
adjacency_(fr.node).size())
316 const size_t nxt =
adjacency_(fr.node)(fr.next_child++);
317 if (nxt == fr.parent)
321 <<
"Rooted_Tree_Topology: filtered graph is not acyclic";
325 stack.
push({nxt, fr.node, 0});
329 <<
"Rooted_Tree_Topology: filtered graph is not connected";
356 noexcept(std::is_nothrow_move_constructible_v<SA>)
376 noexcept(
noexcept(
swap(other)))
395 std::swap(
graph_, other.graph_);
396 std::swap(
root_, other.root_);
397 std::swap(
root_id_, other.root_id_);
398 std::swap(
n_, other.n_);
404 [[nodiscard]]
size_t size() const noexcept {
return n_; }
405 [[nodiscard]]
bool is_empty() const noexcept {
return n_ == 0; }
422 <<
"Rooted_Tree_Topology::id_of: null node";
426 <<
"Rooted_Tree_Topology::id_of: node does not belong to graph";
433 check_id(
id,
"Rooted_Tree_Topology::node_of");
459 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
487 const size_t n =
size();
499 for (
size_t i = 0; i < n; ++i)
511 for (
size_t i = 0; i < n; ++i)
529 size_t visited_count = 1;
537 auto & fr = stack.
top();
546 if (nxt == fr.parent)
550 <<
"Gen_Heavy_Light_Decomposition: filtered graph is not acyclic";
559 stack.
push({nxt, fr.node, 0});
563 <<
"Gen_Heavy_Light_Decomposition: filtered graph is not connected";
565 for (
size_t i = order.
size(); i-- > 0;)
567 const size_t u = order(i);
589 const auto [chain_head, chain_start] = chain_stack.
pop();
591 size_t u = chain_start;
594 head_(u) = chain_head;
601 chain_stack.
push({v, v});
608 <<
"Gen_Heavy_Light_Decomposition: invalid decomposition size";
619 : topology_(g,
root,
std::move(sa))
621 build_decomposition();
630 : topology_(g, nullptr,
std::move(sa))
632 build_decomposition();
635 [[nodiscard]]
size_t size() const noexcept {
return topology_.size(); }
636 [[nodiscard]]
bool is_empty() const noexcept {
return topology_.is_empty(); }
638 [[nodiscard]]
Node *
root() const noexcept {
return topology_.root(); }
639 [[nodiscard]]
size_t root_id() const noexcept {
return topology_.root_id(); }
643 return topology_.node_of(
id);
648 return topology_.id_of(node);
653 topology_.validate_id(
id,
"Gen_Heavy_Light_Decomposition::parent_id");
659 const size_t pid = parent_id(id_of(node));
660 return pid == NONE ? nullptr : node_of(pid);
665 topology_.validate_id(
id,
"Gen_Heavy_Light_Decomposition::depth_of_id");
671 return depth_of_id(id_of(node));
676 topology_.validate_id(
id,
"Gen_Heavy_Light_Decomposition::subtree_size_of_id");
677 return subtree_size_(
id);
682 return subtree_size_of_id(id_of(node));
687 topology_.validate_id(
id,
"Gen_Heavy_Light_Decomposition::heavy_child_id");
693 const size_t cid = heavy_child_id(id_of(node));
694 return cid == NONE ? nullptr : node_of(cid);
697 [[nodiscard]]
size_t head_id(
const size_t id)
const
699 topology_.validate_id(
id,
"Gen_Heavy_Light_Decomposition::head_id");
705 return node_of(head_id(id_of(node)));
710 topology_.validate_id(
id,
"Gen_Heavy_Light_Decomposition::position_of_id");
716 return position_of_id(id_of(node));
722 topology_.validate_id(
id,
"Gen_Heavy_Light_Decomposition::subtree_range_id");
723 const size_t l = pos_(
id);
724 const size_t r =
l + subtree_size_(
id) - 1;
731 return subtree_range_id(id_of(node));
737 const Range r = subtree_range_id(u);
738 const size_t pv = position_of_id(v);
739 return r.left <= pv
and pv <=
r.right;
745 return is_ancestor_id(id_of(u), id_of(v));
749 [[nodiscard]]
size_t lca_id(
size_t u,
size_t v)
const
751 ensure_not_empty(
"Gen_Heavy_Light_Decomposition::lca_id");
752 topology_.validate_id(u,
"Gen_Heavy_Light_Decomposition::lca_id");
753 topology_.validate_id(v,
"Gen_Heavy_Light_Decomposition::lca_id");
755 while (head_(u) != head_(v))
756 if (depth_(head_(u)) >= depth_(head_(v)))
757 u = parent_(head_(u));
759 v = parent_(head_(v));
761 return (depth_(u) <= depth_(v)) ? u : v;
767 return node_of(lca_id(id_of(u), id_of(v)));
771 [[nodiscard]]
size_t distance_id(
const size_t u,
const size_t v)
const
773 const size_t a = lca_id(u, v);
774 return depth_(u) + depth_(v) - 2 * depth_(a);
780 return distance_id(id_of(u), id_of(v));
796 ensure_not_empty(
"Gen_Heavy_Light_Decomposition::for_each_path_segment_id");
797 topology_.validate_id(u,
"Gen_Heavy_Light_Decomposition::for_each_path_segment_id");
798 topology_.validate_id(v,
"Gen_Heavy_Light_Decomposition::for_each_path_segment_id");
802 while (head_(u) != head_(v))
803 if (depth_(head_(u)) >= depth_(head_(v)))
805 visit(pos_(head_(u)), pos_(u),
true);
806 u = parent_(head_(u));
810 down_segments.
push(
Range{pos_(head_(v)), pos_(v)});
811 v = parent_(head_(v));
814 if (depth_(u) >= depth_(v))
815 visit(pos_(v), pos_(u),
true);
817 down_segments.
push(
Range{pos_(u), pos_(v)});
819 while (not down_segments.
is_empty())
821 const auto [left, right] = down_segments.
pop();
822 visit(left, right,
false);
830 for_each_path_segment_id(id_of(u), id_of(v), std::forward<F>(visit));
842 for_each_path_segment_id(u, v,
843 [&](
const size_t l,
const size_t r,
const bool)
875 template <AlephGraph
GT,
895 template <
class Getter>
896 requires std::invocable<Getter, Node *>
and
897 std::convertible_to<std::invoke_result_t<Getter, Node *>,
T>
901 const size_t n = hld.
size();
906 for (
size_t id = 0;
id < n; ++id)
909 base(p) =
static_cast<T>(getter(hld.
node_of(
id)));
920 return static_cast<T>(p->get_info());
953 template <
class Getter>
954 requires std::invocable<Getter, Node *>
and
955 std::convertible_to<std::invoke_result_t<Getter, Node *>,
T>
971 template <
class Getter>
972 requires std::invocable<Getter, Node *>
and
973 std::convertible_to<std::invoke_result_t<Getter, Node *>,
T>
1020 noexcept(
noexcept(
swap(other)))
1038 noexcept(std::is_nothrow_swappable_v<T>
and std::is_nothrow_swappable_v<Op>
1039 and std::is_nothrow_move_assignable_v<Gen_Heavy_Light_Decomposition<GT, SA>>)
1044 if constexpr (
noexcept(std::swap(
hld_, other.hld_))
and std::is_nothrow_swappable_v<T>
1045 and std::is_nothrow_swappable_v<Op>)
1050 std::swap(
hld_, other.hld_);
1096 [[nodiscard]]
size_t size() const noexcept {
return hld_.size(); }
1105 hld_.for_each_path_segment_id(u, v,
1125 const auto range =
hld_.subtree_range_id(
id);
1194 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
1227 const size_t n =
size();
1236 for (
size_t i = 0; i < n; ++i)
1260 const size_t u = stack.
pop();
1282 const size_t total =
nodes.size();
1284 <<
"Gen_Centroid_Decomposition: empty component while choosing centroid";
1286 for (
size_t i = total; i-- > 0;)
1288 const size_t u =
nodes(i);
1302 size_t centroid =
nodes(0);
1303 size_t best_balance = total + 1;
1305 for (
size_t i = 0; i < total; ++i)
1307 const size_t u =
nodes(i);
1320 if (max_part < best_balance)
1322 best_balance = max_part;
1344 const Frame fr = stack.
pop();
1354 stack.
push({v, fr.node, fr.dist + 1});
1361 const size_t n =
size();
1370 size_t parent_centroid;
1377 size_t centroid_count = 0;
1381 const Task task = tasks.
pop();
1392 if (task.parent_centroid ==
NONE)
1400 tasks.
push({v, centroid, task.level + 1});
1404 <<
"Gen_Centroid_Decomposition: invalid centroid tree size";
1410 : topology_(g,
root,
std::move(sa))
1412 build_centroid_tree();
1417 : topology_(g, nullptr,
std::move(sa))
1419 build_centroid_tree();
1437 noexcept(std::is_nothrow_move_constructible_v<Topology>)
1438 : topology_(
std::move(other.topology_)), removed_(
std::move(other.removed_)),
1439 centroid_parent_(
std::move(other.centroid_parent_)),
1440 centroid_level_(
std::move(other.centroid_level_)),
1441 centroid_root_(
std::exchange(other.centroid_root_, NONE)),
1442 local_parent_(
std::move(other.local_parent_)),
1443 local_subtree_(
std::move(other.local_subtree_)),
1444 centroid_ancestors_(
std::move(other.centroid_ancestors_)),
1445 centroid_distances_(
std::move(other.centroid_distances_))
1460 noexcept(
noexcept(
swap(other)))
1475 topology_.swap(other.topology_);
1476 removed_.swap(other.removed_);
1477 centroid_parent_.swap(other.centroid_parent_);
1478 centroid_level_.swap(other.centroid_level_);
1479 std::swap(centroid_root_, other.centroid_root_);
1480 local_parent_.swap(other.local_parent_);
1481 local_subtree_.swap(other.local_subtree_);
1482 centroid_ancestors_.swap(other.centroid_ancestors_);
1483 centroid_distances_.swap(other.centroid_distances_);
1486 [[nodiscard]]
size_t size() const noexcept {
return topology_.size(); }
1487 [[nodiscard]]
bool is_empty() const noexcept {
return topology_.is_empty(); }
1489 [[nodiscard]]
Node *
root() const noexcept {
return topology_.root(); }
1490 [[nodiscard]]
size_t root_id() const noexcept {
return topology_.root_id(); }
1494 return topology_.node_of(
id);
1499 return topology_.id_of(node);
1505 return centroid_root_;
1511 return centroid_root_ == NONE ? nullptr : node_of(centroid_root_);
1517 topology_.validate_id(
id,
"Gen_Centroid_Decomposition::centroid_parent_id");
1518 return centroid_parent_(
id);
1524 const size_t pid = centroid_parent_id(id_of(node));
1525 return pid == NONE ? nullptr : node_of(pid);
1531 topology_.validate_id(
id,
"Gen_Centroid_Decomposition::centroid_level_of_id");
1532 return centroid_level_(
id);
1538 return centroid_level_of_id(id_of(node));
1545 for (
size_t i = 0; i <
size(); ++i)
1546 ret = std::max(ret, centroid_level_(i));
1553 topology_.validate_id(
id,
"Gen_Centroid_Decomposition::centroid_path_length_of_id");
1554 return centroid_ancestors_(
id).size();
1560 return centroid_path_length_of_id(id_of(node));
1566 topology_.validate_id(
id,
"Gen_Centroid_Decomposition::centroid_ancestors_of_id");
1567 return centroid_ancestors_(
id);
1573 topology_.validate_id(
id,
"Gen_Centroid_Decomposition::centroid_distances_of_id");
1574 return centroid_distances_(
id);
1580 return centroid_ancestors_of_id(id_of(node));
1586 return centroid_distances_of_id(id_of(node));
1591 const size_t node)
const
1593 topology_.validate_id(ancestor,
"Gen_Centroid_Decomposition::is_centroid_ancestor_id");
1594 topology_.validate_id(node,
"Gen_Centroid_Decomposition::is_centroid_ancestor_id");
1596 const auto &
chain = centroid_ancestors_(node);
1597 for (
size_t i = 0; i <
chain.size(); ++i)
1598 if (
chain(i) == ancestor)
1609 const size_t centroid)
const
1611 topology_.validate_id(node,
"Gen_Centroid_Decomposition::distance_to_centroid_id");
1612 topology_.validate_id(centroid,
"Gen_Centroid_Decomposition::distance_to_centroid_id");
1614 const auto &
chain = centroid_ancestors_(node);
1615 const auto & dists = centroid_distances_(node);
1617 for (
size_t i = 0; i <
chain.size(); ++i)
1618 if (
chain(i) == centroid)
1631 ensure_not_empty(
"Gen_Centroid_Decomposition::for_each_centroid_ancestor_id");
1632 topology_.validate_id(node,
"Gen_Centroid_Decomposition::for_each_centroid_ancestor_id");
1634 const auto &
chain = centroid_ancestors_(node);
1635 const auto & dists = centroid_distances_(node);
1638 <<
"Gen_Centroid_Decomposition: invalid centroid annotation state";
1640 for (
size_t i = 0; i <
chain.size(); ++i)
1641 f(
chain(i), dists(i), i);
1651 for_each_centroid_ancestor_id(id_of(node), std::forward<F>(f));
1657 template <
class GT,
class SA = Dft_Show_Arc<GT>>
1668 template <
class GT,
class SA = Dft_Show_Arc<GT>>
Exception handling system with formatted messages for Aleph-w.
#define ah_runtime_error_unless(C)
Throws std::runtime_error if condition does NOT hold.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
C++20 concepts for the protocol shared by graph algorithms.
Standard functor implementations and comparison objects.
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
size_t size_t int32_t value
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
void swap(Array &s) noexcept
Swap this with s
static Array create(const size_t n)
Create an array with n logical elements.
T & append(const T &data)
Append a copy of data
void reserve(size_t cap)
Reserves cap cells into the array.
Dynamic stack of elements of generic type T based on a singly linked list.
T & top()
Return a modifiable reference to the top item of the stack.
bool is_empty() const noexcept
Check if the stack is empty.
T pop()
Remove and return the top item of the stack.
T & push(const T &data)
Push an item by copy onto the top of the stack.
Generic key-value map implemented on top of a binary search tree.
typename Base::Iterator Iterator
Pair * search(const Key &key) noexcept(nothrow_search)
Collect all keys.
Pair * insert(const Key &key, const Data &data)
Insert a key-value pair.
void next_ne() noexcept(shows_ne)
Advances the iterator to the next filtered element, as next() does.
Centroid decomposition over a rooted tree represented as an Aleph graph.
Node * centroid_parent(const Node *node) const
Parent centroid of node (or nullptr if centroid root).
size_t centroid_path_length_of(const Node *node) const
Number of centroid ancestors stored for node.
Array< size_t > centroid_parent_
Array< size_t > centroid_level_
Array< Array< size_t > > centroid_distances_
bool is_empty() const noexcept
size_t centroid_level_of_id(const size_t id) const
Level of centroid id in centroid tree (root level = 0).
void build_centroid_tree()
const Array< size_t > & centroid_ancestors_of(const Node *node) const
Centroid ancestors of node from centroid root down to local centroid.
Node * centroid_root() const noexcept
Root centroid node of the centroid tree (or nullptr if empty).
bool is_centroid_ancestor_id(const size_t ancestor, const size_t node) const
True iff ancestor is in the centroid-ancestor chain of node.
void ensure_not_empty(const char *where) const
size_t centroid_level_of(const Node *node) const
Level of centroid node in centroid tree (root level = 0).
size_t centroid_root_id() const noexcept
Root centroid ID of the centroid tree (or NONE if empty).
Gen_Centroid_Decomposition(const GT &g, Node *root, SA sa=SA())
Construct using an explicit root node.
const Array< size_t > & centroid_ancestors_of_id(const size_t id) const
Centroid ancestors of node ID from centroid root down to local centroid.
Node * node_of(const size_t id) const
Array< size_t > local_subtree_
size_t centroid_parent_id(const size_t id) const
Parent centroid ID of id (or NONE if centroid root).
size_t centroid_path_length_of_id(const size_t id) const
Number of centroid ancestors stored for node ID.
Gen_Centroid_Decomposition(Gen_Centroid_Decomposition &&other) noexcept(std::is_nothrow_move_constructible_v< Topology >)
Take the centroid tree of another decomposition, which is left empty.
const Array< size_t > & centroid_distances_of(const Node *node) const
Distances to centroid ancestors (aligned with centroid_ancestors_of).
size_t max_centroid_level() const noexcept
Maximum centroid-tree level.
void swap(Gen_Centroid_Decomposition &other) noexcept(std::is_nothrow_swappable_v< SA >)
Exchange in O(1) this decomposition and another.
size_t distance_to_centroid_id(const size_t node, const size_t centroid) const
Distance from node ID to a centroid ancestor ID.
Node * root() const noexcept
Array< size_t > local_parent_
void append_centroid_annotations(const size_t centroid)
static constexpr size_t NONE
void for_each_centroid_ancestor_id(const size_t node, F &&f) const
Visit each centroid ancestor of node ID.
size_t id_of(const Node *node) const
Array< size_t > collect_component_nodes(const size_t start)
Gen_Centroid_Decomposition(const Gen_Centroid_Decomposition &other)=default
Copy the centroid tree of another decomposition.
void for_each_centroid_ancestor(const Node *node, F &&f) const
Visit each centroid ancestor of node.
const Array< size_t > & centroid_distances_of_id(const size_t id) const
Distances to centroid ancestors (aligned with centroid_ancestors_of_id).
Gen_Centroid_Decomposition(const GT &g, SA sa=SA())
Construct using the first graph node as root.
size_t size() const noexcept
size_t choose_centroid(const Array< size_t > &nodes)
Array< Array< size_t > > centroid_ancestors_
size_t root_id() const noexcept
Segment-tree-powered path/subtree queries over an HLD layout.
Gen_Heavy_Light_Decomposition< GT, SA > hld_
T query_subtree(const Node *node) const
Subtree query for node in O(log n).
static Array< T > build_base_from_node_info(const Gen_Heavy_Light_Decomposition< GT, SA > &hld)
Gen_HLD_Path_Query & operator=(const Gen_HLD_Path_Query &other)=default
Copy the decomposition and the values of another engine.
void set_node(const Node *node, const T &value)
Point assignment: a[node] = value.
T query_path(const Node *u, const Node *v) const
Path query between two nodes in O(log^2 n).
void update_node(const Node *node, const T &delta)
Point update: a[node] = Op(a[node], delta).
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(Gen_HLD_Path_Query &&other)=default
Take the decomposition and the values of another engine, which is left empty.
void ensure_not_empty(const char *where) const
const Gen_Heavy_Light_Decomposition< GT, SA > & decomposition() 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).
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().
T get_node_id(const size_t id) const
Return current value at node ID.
void swap_all_or_none(Gen_HLD_Path_Query &other)
size_t size() const noexcept
T query_subtree_id(const size_t id) const
Subtree query for node ID in O(log n).
void update_node_id(const size_t id, const T &delta)
Point update: a[id] = Op(a[id], delta).
bool is_empty() const noexcept
void set_node_id(const size_t id, const T &value)
Point assignment: a[id] = value.
Gen_HLD_Path_Query(const Gen_HLD_Path_Query &other)=default
Copy the decomposition and the values of another engine.
Gen_Segment_Tree< T, Op > segment_tree_
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)
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.
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.
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).
T get_node(const Node *node) const
Return current value at node.
Heavy-Light Decomposition over a rooted tree represented as an Aleph graph.
Gen_Heavy_Light_Decomposition(const GT &g, SA sa=SA())
Construct using the first graph node as root.
size_t position_of(const Node *node) const
static constexpr size_t NONE
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.
Array< size_t > subtree_size_
size_t parent_id(const size_t id) const
size_t root_id() const noexcept
size_t head_id(const size_t id) const
size_t distance_id(const size_t u, const size_t v) const
Distance (number of edges) between two node IDs.
size_t lca_id(size_t u, size_t v) const
Lowest common ancestor in O(log n).
size_t position_of_id(const size_t id) const
Node * head_of(const Node *node) const
size_t distance(const Node *u, const Node *v) const
Distance (number of edges) between two nodes.
size_t subtree_size_of_id(const size_t id) const
size_t depth_of_id(const size_t id) const
size_t heavy_child_id(const size_t id) const
void ensure_not_empty(const char *where) const
Node * lca(const Node *u, const Node *v) const
Lowest common ancestor in O(log n).
Node * heavy_child(const Node *node) const
bool is_ancestor(const Node *u, const Node *v) const
True iff u is ancestor of v in the rooted tree.
Range subtree_range(const Node *node) const
Base-array range of a full subtree (inclusive endpoints).
size_t id_of(const Node *node) const
size_t depth_of(const Node *node) const
Gen_Heavy_Light_Decomposition(const GT &g, Node *root, SA sa=SA())
Construct using an explicit root node.
Node * node_of(const size_t id) const
size_t subtree_size_of(const Node *node) const
Range subtree_range_id(const size_t id) const
Base-array range of a full subtree (inclusive endpoints).
Node * parent_of(const Node *node) const
Node * root() const noexcept
bool is_ancestor_id(const size_t u, const size_t v) const
True iff u is ancestor of v in the rooted tree.
void for_each_path_segment(const Node *u, const Node *v, F &&visit) const
Enumerate path segments from u to v in path order.
void for_each_path_segment_undirected_id(const size_t u, const size_t v, F &&visit) const
Enumerate path segments ignoring direction.
void build_decomposition()
size_t size() const noexcept
bool is_empty() const noexcept
Segment tree over an arbitrary associative binary operation.
typename Node::Node_Type Node_Type
The arc class type.
Graph_Node< Node_Info > Node
The graph type.
Graph_Arc< Arc_Info > Arc
The node class type.
Filtered iterator on the nodes of a graph.
Node * node_of(const size_t id) const
bool is_empty() const noexcept
void validate_id(const size_t id, const char *where) const
void swap(Rooted_Tree_Topology &other) noexcept(std::is_nothrow_swappable_v< SA >)
Exchange in O(1) this topology and another.
MapOLhash< Node *, size_t > node_to_id_
std::pair< size_t, size_t > Pair_Key
const Array< Node * > & id_to_node() const noexcept
void build_simple_adjacency()
void validate_connected_acyclic() const
size_t root_id() const noexcept
Rooted_Tree_Topology(const GT &g, Node *root, SA sa=SA())
static constexpr size_t NONE
size_t size() const noexcept
Rooted_Tree_Topology(const Rooted_Tree_Topology &other)=default
Copy the topology of another tree.
size_t id_of(const Node *node) const
Node * root() const noexcept
Rooted_Tree_Topology & operator=(const Rooted_Tree_Topology &other)=default
Copy the topology of another tree.
Array< Array< size_t > > adjacency_
const Array< Array< size_t > > & adjacency() const noexcept
Array< Node * > id_to_node_
void check_id(const size_t id, const char *where) const
static Pair_Key normalize_pair(size_t u, size_t v) noexcept
Rooted_Tree_Topology(Rooted_Tree_Topology &&other) noexcept(std::is_nothrow_move_constructible_v< SA >)
Take the topology of another tree, which is left empty.
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
static Tree_Node< int > * chain(size_t n)
__gmp_expr< T, __gmp_binary_expr< __gmp_expr< T, U >, unsigned long int, __gmp_root_function > > root(const __gmp_expr< T, U > &expr, unsigned long int l)
DynArray< Graph::Node * > nodes
Main namespace for Aleph-w library functions.
T & swap(T &t1, T &t2)
Generic swap using object's swap method.
size_t size(Node *root) noexcept
See compute_cardinality_rec(Node * root).
std::decay_t< typename HeadC::Item_Type > T
and
Check uniqueness with explicit hash + equality functors.
Container< T > range(const T start, const T end, const T step=1)
Generate a range of values [start, end] with a given step.
Filtered iterator on all the arcs of a graph.
Default filter for filtered iterators on arcs.
Open addressing hash map using linear probing.
Data & find(const Key &key)
Find and return the value for a key.
Pair * search(const Key &key) noexcept(nothrow_search< const Key & >)
Search for a key in the map.
Pair * insert(const Key &key, const Data &data)
Insert a key-value pair (copy semantics).
Task with priority for job scheduling.
Dynamic array container with automatic resizing.
Dynamic stack implementation based on linked lists.
Dynamic map with open hashing.
Dynamic key-value map based on balanced binary search trees.
Generic graph and digraph implementations.
Segment trees for dynamic range queries with lazy propagation.