51#include <lal/graphs/tree_type.hpp>
52#include <lal/graphs/rooted_tree.hpp>
53#include <lal/graphs/free_tree.hpp>
54#include <lal/internal/data_array.hpp>
62 std::is_base_of_v<graphs::free_tree, T> ||
63 std::is_base_of_v<graphs::rooted_tree, T>,
67(
const T& t, std::array<bool, graphs::__tree_type_size>& array)
75 array[
static_cast<size_t>(tt)] =
true;
80 const auto get_only_neighbour =
82 if constexpr (std::is_base_of_v<lal::graphs::free_tree, T>) {
83 return t.get_neighbours(u)[0];
86 return (t.get_out_degree(u) == 0 ?
87 t.get_in_neighbours(u)[0] :
88 t.get_out_neighbours(u)[0]
96 const uint32_t N = t.get_num_nodes();
127 bool is_linear =
false;
128 bool is_star =
false;
129 bool is_quasistar =
false;
130 bool is_bistar =
false;
131 bool is_caterpillar =
false;
132 bool is_spider =
false;
135 uint32_t n_deg_eq_1 = 0;
136 uint32_t n_deg_eq_2 = 0;
137 uint32_t n_deg_ge_2 = 0;
138 uint32_t n_deg_ge_3 = 0;
141 data_array<int32_t> deg_internal(N, 0);
146 const int32_t du =
static_cast<int32_t
>(t.get_degree(u));
147 deg_internal[u] += (du > 1)*du;
149 n_deg_eq_1 += du == 1;
150 n_deg_eq_2 += du == 2;
151 n_deg_ge_2 += du > 1;
152 n_deg_ge_3 += du > 2;
157 deg_internal[ get_only_neighbour(u) ] -= 1;
162 if (n_deg_eq_1 == 2) {
166 assert(n_deg_ge_2 == N - 2);
169 is_caterpillar =
true;
173 if (n_deg_ge_2 == 2 and N - n_deg_ge_2 == n_deg_eq_1) {
175 is_caterpillar =
true;
179 if (N - n_deg_ge_2 == n_deg_eq_1 and
181 (n_deg_eq_2 == 2 and n_deg_ge_3 == 0) or
182 (n_deg_ge_3 == 1 and n_deg_eq_2 == 1)
187 is_caterpillar =
true;
191 if (n_deg_ge_2 == 1 and n_deg_eq_1 == N - 1) {
193 is_caterpillar =
true;
197 if (n_deg_ge_3 == 1 and n_deg_eq_1 + n_deg_eq_2 == N - 1) {
201 if (not is_caterpillar) {
210 n1 += deg_internal[u] == 1;
213 is_caterpillar = n1 == 2 or n1 == 0;
tree_type
Enumeration of several types of trees.
Definition tree_type.hpp:55
@ caterpillar
Caterpillar trees.
@ quasistar
Quasi star trees.
@ unknown
The tree could not be classified.
Main namespace of the library.
Definition definitions.hpp:48
uint32_t node
Node type.
Definition definitions.hpp:51