48#include <lal/graphs/rooted_tree.hpp>
49#include <lal/detail/macros/basic_convert.hpp>
50#include <lal/detail/array.hpp>
72 std::enable_if_t< std::is_base_of_v<graphs::tree, tree_t>,
bool> =
true
74[[nodiscard]]
char fast_non_iso(
const tree_t& t1,
const tree_t& t2)
noexcept
77 if (t1.get_num_nodes() != t2.get_num_nodes()) {
return 1; }
79 const uint64_t n = t1.get_num_nodes();
82 if (n <= 2) {
return 0; }
88 uint64_t maxdeg_t1 = 0;
89 uint64_t maxdeg_t2 = 0;
90 for (
node u = 0; u < n; ++u) {
91 const uint64_t ku1 =
to_uint64(t1.get_degree(u));
92 const uint64_t ku2 =
to_uint64(t2.get_degree(u));
94 nL_t1 += t1.get_degree(u) == 1;
95 nL_t2 += t2.get_degree(u) == 1;
98 maxdeg_t1 = (maxdeg_t1 < ku1 ? ku1 : maxdeg_t1);
99 maxdeg_t2 = (maxdeg_t2 < ku2 ? ku2 : maxdeg_t2);
103 if (nL_t1 != nL_t2) {
return 1; }
105 if (maxdeg_t1 != maxdeg_t2) {
return 1; }
107 if (k2_t1 != k2_t2) {
return 1; }
141 if (t.get_out_degree(u) == 0) {
142 keep_name_of[u] =
"10";
147 const std::size_t begin_idx = idx;
148 for (
node v : t.get_out_neighbors(u)) {
152 aux_memory_for_names[idx] = keep_name_of[v];
155 std::sort(&aux_memory_for_names[begin_idx], &aux_memory_for_names[idx]);
158 keep_name_of[u] =
"1";
159 for (std::size_t j = begin_idx; j < idx; ++j) {
160 keep_name_of[u] += aux_memory_for_names[j];
162 keep_name_of[u] +=
"0";
189 if (t.get_out_degree(u) == 0) {
190 return std::string(
"10");
194 const std::size_t begin_idx = idx;
195 for (
node v : t.get_out_neighbors(u)) {
200 std::sort(&names[begin_idx], &names[idx]);
203 std::string name =
"1";
204 for (std::size_t j = begin_idx; j < idx; ++j) {
223 if (discard == 0) {
return true; }
224 if (discard == 1) {
return false; }
227 const std::string name_r1 =
assign_name(t1, t1.get_root(), names, 0);
228 const std::string name_r2 =
assign_name(t2, t2.get_root(), names, 0);
229 return name_r1 == name_r2;
Rooted tree graph class.
Definition rooted_tree.hpp:109
char fast_non_iso(const tree_t &t1, const tree_t &t2) noexcept
Fast tree non-isomorphism test.
Definition tree_isomorphism.hpp:74
std::string assign_name(const graphs::rooted_tree &t, const node u, array< std::string > &names, std::size_t idx) noexcept
Assigns a name to node 'u', root of the current subtree.
Definition tree_isomorphism.hpp:181
bool are_rooted_trees_isomorphic(const graphs::rooted_tree &t1, const graphs::rooted_tree &t2) noexcept
Test whether two rooted trees are isomorphic or not.
Definition tree_isomorphism.hpp:219
void assign_name_and_keep(const graphs::rooted_tree &t, const node u, std::size_t idx, array< std::string > &aux_memory_for_names, array< std::string > &keep_name_of) noexcept
Assigns a name to node 'u', root of the current subtree.
Definition tree_isomorphism.hpp:132
constexpr uint64_t to_uint64(const T &t) noexcept
Conversion to uint64_t.
Definition basic_convert.hpp:52
Main namespace of the library.
Definition basic_types.hpp:48
uint64_t node
Node type. See Node / Vertex page for further details.
Definition basic_types.hpp:51
Wrapper of a C array for automatic deallocation of memory.
Definition array.hpp:59