50#include <lal/definitions.hpp>
51#include <lal/graphs/rooted_tree.hpp>
52#include <lal/graphs/free_tree.hpp>
53#include <lal/internal/graphs/traversal.hpp>
62void UnionFind_update_roots_after_add
66 uint32_t *
const root_size
74 node parent, child, new_root;
76 const node root_u = root_of[u];
77 const node root_v = root_of[v];
79 const uint32_t size_u = root_size[root_u];
80 const uint32_t size_v = root_size[root_v];
81 const uint32_t new_size = size_u + size_v;
83 if (size_u < size_v) {
84 root_of[root_u] = root_v;
88 root_size[new_root] = new_size;
91 parent = v; child = u;
94 root_of[root_v] = root_u;
98 root_size[new_root] = new_size;
101 parent = u; child = v;
106 internal::BFS<T> bfs(t);
107 bfs.set_use_rev_edges(t.is_directed());
108 bfs.set_process_current(
109 [&](
const auto&,
node w) ->
void { root_of[w] = new_root; }
111 bfs.set_visited(parent, 1);
119void UnionFind_update_roots_after_remove
122 node *
const root_of,
123 uint32_t *
const root_size
128 assert(root_of[u] == root_of[v]);
131 const uint32_t size_uv = root_size[root_of[u]];
133 internal::BFS<T> bfs(t);
140 bfs.set_use_rev_edges(t.is_directed());
141 bfs.set_process_current(
142 [&](
const auto&,
node w) ->
void { root_of[w] = u; ++size_u; }
146 root_size[u] = size_u;
152 bfs.set_process_current(
153 [&](
const auto&,
node w) ->
void { root_of[w] = v; }
157 root_size[v] = size_uv - size_u;
174void UnionFind_update_roots_before_remove_all_incident_to
177 node *
const root_of,
178 uint32_t *
const root_size
181 internal::BFS<T> bfs(t);
182 bfs.set_use_rev_edges(t.is_directed());
184 bfs.set_visited(u, 1);
186 uint32_t size_cc_v = 0;
187 bfs.set_process_current(
188 [&](
const auto&,
node w) ->
void { root_of[w] = v; ++size_cc_v; }
193 root_size[v] = size_cc_v;
202void UnionFind_update_roots_before_remove_all_incident_to
205 node *
const root_of,
206 uint32_t *
const root_size
209 if constexpr (std::is_base_of_v<graphs::free_tree, T>) {
210 for (
node v : t.get_neighbours(u)) {
213 __lal::UnionFind_update_roots_before_remove_all_incident_to(
214 t, u, v, root_of, root_size
219 for (
node v : t.get_in_neighbours(u)) {
222 __lal::UnionFind_update_roots_before_remove_all_incident_to(
223 t, u, v, root_of, root_size
226 for (
node v : t.get_out_neighbours(u)) {
229 __lal::UnionFind_update_roots_before_remove_all_incident_to(
230 t, u, v, root_of, root_size
Main namespace of the library.
Definition definitions.hpp:48
uint32_t node
Node type.
Definition definitions.hpp:51