50#include <lal/basic_types.hpp>
51#include <lal/graphs/rooted_tree.hpp>
52#include <lal/graphs/free_tree.hpp>
53#include <lal/detail/graphs/traversal.hpp>
72template <
class tree_t>
75 const tree_t& t,
const node u,
const node v,
77 uint64_t *
const root_size
86 node parent, child, new_root;
88 const node root_u = root_of[u];
89 const node root_v = root_of[v];
91 const uint64_t size_u = root_size[root_u];
92 const uint64_t size_v = root_size[root_v];
93 const uint64_t new_size = size_u + size_v;
95 if (size_u < size_v) {
96 root_of[root_u] = root_v;
100 root_size[new_root] = new_size;
103 parent = v; child = u;
106 root_of[root_v] = root_u;
110 root_size[new_root] = new_size;
113 parent = u; child = v;
141template <
class tree_t>
144 const tree_t& t,
const node u,
const node v,
145 node *
const root_of,
146 uint64_t *
const root_size
152 assert(root_of[u] == root_of[v]);
155 const uint64_t size_uv = root_size[root_of[u]];
163 uint64_t size_cc_u = 0;
166 [&](
const auto&,
node w) ->
void {
173 root_size[u] = size_cc_u;
186 root_size[v] = size_uv - size_cc_u;
209template <
class tree_t>
213 node *
const root_of,
214 uint64_t *
const root_size
218 uint64_t size_cc_v = 0;
219 bfs.set_process_current(
220 [&](
const auto&,
node w) ->
void {
228 root_size[v] = size_cc_v;
249template <
typename tree_t>
252 const tree_t& t,
node u,
253 node *
const root_of,
254 uint64_t *
const root_size
263 if constexpr (std::is_base_of_v<graphs::free_tree, tree_t>) {
264 for (
node v : t.get_neighbours(u)) {
268 (bfs, v, root_of, root_size);
272 for (
node v : t.get_in_neighbours(u)) {
276 (bfs, v, root_of, root_size);
278 for (
node v : t.get_out_neighbours(u)) {
282 (bfs, v, root_of, root_size);
Abstract graph Breadth-First Search traversal.
Definition: traversal.hpp:89
void set_visited(node u, char vis) noexcept
Set node u as visited or not.
Definition: traversal.hpp:232
void set_process_current(const BFS_process_one &f) noexcept
Set the function that controls the processing of the current node.
Definition: traversal.hpp:186
void start_at(node source) noexcept
Start traversal at a given node.
Definition: traversal.hpp:152
void set_use_rev_edges(bool use) noexcept
Set whether the traversal can use reversed edges.
Definition: traversal.hpp:173
void update_unionfind_after_remove_edge(const tree_t &t, const node u, const node v, node *const root_of, uint64_t *const root_size) noexcept
Updates Union-Find after an edge removal.
Definition: union_find.hpp:143
void update_unionfind_before_remove_edges_incident_to(BFS< tree_t > &bfs, node v, node *const root_of, uint64_t *const root_size) noexcept
Update Union-Find after a vertex removal.
Definition: union_find.hpp:211
void update_unionfind_after_add_edge(const tree_t &t, const node u, const node v, node *const root_of, uint64_t *const root_size) noexcept
Update the Union-Find data structure after an edge addition to a tree.
Definition: union_find.hpp:74
Main namespace of the library.
Definition: basic_types.hpp:50
uint64_t node
Node type. See Node / Vertex page for further details.
Definition: basic_types.hpp:53