11#include <lal/graphs/rooted_tree.hpp>
12#include <lal/internal/data_array.hpp>
30 std::is_base_of_v<graphs::free_tree, T> ||
31 std::is_base_of_v<graphs::rooted_tree, T>,
35char fast_non_iso(
const T& t1,
const T& t2)
noexcept {
37 if (t1.get_num_nodes() != t2.get_num_nodes()) {
return 1; }
39 if constexpr (std::is_base_of_v<lal::graphs::rooted_tree, T>) {
41 if (not t1.is_orientation_valid() or not t2.is_orientation_valid()) {
46 const uint32_t n = t1.get_num_nodes();
49 if (n <= 2) {
return 0; }
55 uint64_t maxdeg_t1 = 0;
56 uint64_t maxdeg_t2 = 0;
57 for (
node u = 0; u < n; ++u) {
58 const uint64_t ku1 =
static_cast<uint64_t
>(t1.get_degree(u));
59 const uint64_t ku2 =
static_cast<uint64_t
>(t2.get_degree(u));
61 nL_t1 += t1.get_degree(u) == 1;
62 nL_t2 += t2.get_degree(u) == 1;
65 maxdeg_t1 = (maxdeg_t1 < ku1 ? ku1 : maxdeg_t1);
66 maxdeg_t2 = (maxdeg_t2 < ku2 ? ku2 : maxdeg_t2);
70 if (nL_t1 != nL_t2) {
return 1; }
72 if (maxdeg_t1 != maxdeg_t2) {
return 1; }
74 if (k2_t1 != k2_t2) {
return 1; }
99void assign_name_and_keep(
100 const graphs::rooted_tree& t,
node u,
101 std::string *
const aux_memory_for_names,
size_t idx,
102 std::string *
const keep_name_of
106 if (t.get_out_degree(u) == 0) {
107 keep_name_of[u] =
"10";
112 const size_t begin_idx = idx;
113 for (
node v : t.get_out_neighbours(u)) {
115 assign_name_and_keep(t,v, aux_memory_for_names, idx+1, keep_name_of);
117 aux_memory_for_names[idx] = keep_name_of[v];
120 std::sort(&aux_memory_for_names[begin_idx], &aux_memory_for_names[idx]);
123 std::string name =
"1";
124 for (
size_t j = begin_idx; j < idx; ++j) {
125 name += aux_memory_for_names[j];
128 keep_name_of[u] = name;
147std::string assign_name
148(
const graphs::rooted_tree& t,
node u, std::string *
const names,
size_t idx)
151 if (t.get_out_degree(u) == 0) {
152 return std::string(
"10");
156 const size_t begin_idx = idx;
157 for (
node v : t.get_out_neighbours(u)) {
159 names[idx] = assign_name(t,v, names, idx+1);
162 std::sort(&names[begin_idx], &names[idx]);
165 std::string name =
"1";
166 for (
size_t j = begin_idx; j < idx; ++j) {
175bool are_full_trees_isomorphic
176(
const graphs::rooted_tree& t1,
const graphs::rooted_tree& t2)
179 const auto discard = internal::fast_non_iso(t1,t2);
180 if (discard == 0) {
return true; }
181 if (discard == 1) {
return false; }
183 const uint32_t n = t1.get_num_nodes();
184 data_array<std::string> names(n);
185 const std::string name_r1 = assign_name(t1, t1.get_root(), names.data, 0);
186 const std::string name_r2 = assign_name(t2, t2.get_root(), names.data, 0);
187 return name_r1 == name_r2;
Main namespace of the library.
Definition definitions.hpp:48
uint32_t node
Node type.
Definition definitions.hpp:51