51#include <lal/graphs/rooted_tree.hpp>
52#include <lal/graphs/free_tree.hpp>
53#include <lal/internal/macros.hpp>
73 std::is_base_of_v<graphs::rooted_tree, T> ||
74 std::is_base_of_v<graphs::free_tree, T>,
78(
const T& t,
const node u,
const node v, uint32_t *
const sizes)
82 if constexpr (std::is_base_of_v<graphs::rooted_tree, T>) {
83 for (
const node w : t.get_out_neighbours(v)) {
84 if (w == u) {
continue; }
85 get_size_subtrees(t, v, w, sizes);
88 for (
const node w : t.get_in_neighbours(v)) {
89 if (w == u) {
continue; }
90 get_size_subtrees(t, v, w, sizes);
95 for (
const node w : t.get_neighbours(v)) {
96 if (w == u) {
continue; }
97 get_size_subtrees(t, v, w, sizes);
120 std::is_base_of_v<graphs::rooted_tree, T> ||
121 std::is_base_of_v<graphs::free_tree, T>,
124void get_size_subtrees
125(
const T& t,
node r, uint32_t *
const sizes)
128 assert(sizes !=
nullptr);
130 __lal::get_size_subtrees(t, t.get_num_nodes(), r, sizes);
162 typename Iterator_Type,
165 std::is_base_of_v<graphs::rooted_tree, tree_type> ||
166 std::is_base_of_v<graphs::free_tree, tree_type>
168 && is_pointer_iterator_v<std::pair<edge,uint32_t>, Iterator_Type>
173uint32_t calculate_bidirectional_sizes
174(
const tree_type& t,
const uint32_t n,
const node u,
const node v, Iterator_Type& it)
177 if constexpr (std::is_base_of_v<graphs::rooted_tree, tree_type>) {
178 for (
const node w : t.get_out_neighbours(v)) {
179 if (w == u) {
continue; }
180 s += calculate_bidirectional_sizes(t,n, v, w, it);
182 for (
const node w : t.get_in_neighbours(v)) {
183 if (w == u) {
continue; }
184 s += calculate_bidirectional_sizes(t,n, v, w, it);
188 for (
const node w : t.get_neighbours(v)) {
189 if (w == u) {
continue; }
190 s += calculate_bidirectional_sizes(t,n, v, w, it);
194 *it++ = std::make_pair(
edge(u,v), s);
195 *it++ = std::make_pair(
edge(v,u), n - s);
228 typename Iterated_Type,
229 typename Iterator_Type,
232 std::is_base_of_v<graphs::rooted_tree, tree_type> ||
233 std::is_base_of_v<graphs::free_tree, tree_type>
236 is_pointer_iterator_v<Iterated_Type, Iterator_Type>
241uint32_t calculate_bidirectional_sizes(
245 const std::function<
void (Iterated_Type&,
const edge&, uint32_t)> F,
250 if constexpr (std::is_base_of_v<graphs::rooted_tree, tree_type>) {
251 for (
const node w : t.get_out_neighbours(v)) {
252 if (w == u) {
continue; }
253 s += calculate_bidirectional_sizes(t,n, v, w, F, it);
255 for (
const node w : t.get_in_neighbours(v)) {
256 if (w == u) {
continue; }
257 s += calculate_bidirectional_sizes(t,n, v, w, F, it);
261 for (
const node w : t.get_neighbours(v)) {
262 if (w == u) {
continue; }
263 s += calculate_bidirectional_sizes(t,n, v, w, F, it);
267 F(*it,
edge(u,v), s);
269 F(*it,
edge(v,u), n - s);
311 typename Iterator_Type,
314 std::is_base_of_v<graphs::rooted_tree, tree_type> ||
315 std::is_base_of_v<graphs::free_tree, tree_type>
317 && is_pointer_iterator_v<std::pair<edge,uint32_t>, Iterator_Type>
322void calculate_bidirectional_sizes
323(
const tree_type& t,
const uint32_t n,
const node x, Iterator_Type& it)
325 if constexpr (std::is_base_of_v<graphs::rooted_tree, tree_type>) {
326 for (
node y : t.get_out_neighbours(x)) {
327 __lal::calculate_bidirectional_sizes<tree_type, Iterator_Type>
330 for (
node y : t.get_in_neighbours(x)) {
331 __lal::calculate_bidirectional_sizes<tree_type, Iterator_Type>
336 for (
node y : t.get_neighbours(x)) {
337 __lal::calculate_bidirectional_sizes<tree_type, Iterator_Type>
380 typename Iterated_Type,
381 typename Iterator_Type,
384 std::is_base_of_v<graphs::rooted_tree, tree_type> ||
385 std::is_base_of_v<graphs::free_tree, tree_type>
387 && is_pointer_iterator_v<Iterated_Type, Iterator_Type>
392void calculate_bidirectional_sizes(
394 const uint32_t n,
const node x,
395 const std::function<
void (Iterated_Type&,
const edge&, uint32_t)> F,
399 if constexpr (std::is_base_of_v<graphs::rooted_tree, tree_type>) {
400 for (
node y : t.get_out_neighbours(x)) {
401 __lal::calculate_bidirectional_sizes<tree_type, Iterated_Type, Iterator_Type>
404 for (
node y : t.get_in_neighbours(x)) {
405 __lal::calculate_bidirectional_sizes<tree_type, Iterated_Type, Iterator_Type>
410 for (
node y : t.get_neighbours(x)) {
411 __lal::calculate_bidirectional_sizes<tree_type, Iterated_Type, Iterator_Type>
tree_type
Enumeration of several types of trees.
Definition tree_type.hpp:55
Main namespace of the library.
Definition definitions.hpp:48
std::pair< node, node > edge
Edge type.
Definition definitions.hpp:75
uint32_t node
Node type.
Definition definitions.hpp:51