57#include <lal/linear_arrangement.hpp>
58#include <lal/graphs/rooted_tree.hpp>
59#include <lal/detail/data_array.hpp>
60#include <lal/iterators/E_iterator.hpp>
61#include <lal/detail/graphs/size_subtrees.hpp>
62#include <lal/detail/sorting/counting_sort.hpp>
63#include <lal/detail/properties/tree_centroid.hpp>
76inline constexpr place PLACE_LEFT_OF = 0;
77inline constexpr place PLACE_RIGHT_OF = 1;
78inline constexpr place PLACE_NONE_OF = 2;
80inline constexpr side RIGHT_SIDE = 0;
81inline constexpr side LEFT_SIDE = 1;
85inline constexpr side other_side(
side s)
noexcept {
return ((s + 1)&0x1); }
114template <
typename sort_type>
117 std::vector<std::vector<node_size>>& L
121 const uint64_t n = t.get_num_nodes();
122 const node r = t.get_root();
130 const std::size_t k = t.are_size_subtrees_valid() ? 0 : t.get_num_nodes();
134 auto it = edge_list.
begin();
137 if (t.are_size_subtrees_valid()) {
139 while (not E_it.
end()) {
141 const node v = e.second;
142 const uint64_t suv = t.get_num_nodes_subtree(v);
152 while (not E_it.
end()) {
154 const node v = e.second;
155 const uint64_t suv = size_subtrees[v];
167 edge_list.
begin(), edge_list.
end(), n,
168 [](
const edge_size& T) -> std::size_t {
return T.size; },
176 for (
const auto& T : edge_list) {
177 const auto [u, v] = T.
e;
178 const uint64_t nv = T.size;
179 L[u].push_back({v,nv});
181 assert(t.has_edge(u,v));
186 for (
node u = 0; u < n; ++u) {
187 assert(L[u].size() == t.get_out_degree(u));
Rooted tree graph class.
Definition: rooted_tree.hpp:103
Iterator over the set of edges of a graph.
Definition: E_iterator.hpp:97
void next() noexcept
Moves the iterator to the next edge.
Definition: E_iterator.hpp:142
bool end() const noexcept
Returns true if the end of the iteration was reached.
Definition: E_iterator.hpp:117
const edge & get_edge() const noexcept
Returns the current edge.
Definition: E_iterator.hpp:120
unsigned char side
Useful typedef to denote relative position.
Definition: Dopt_utils.hpp:74
constexpr char NO_ANCHOR
The tree is not anchored.
Definition: Dopt_utils.hpp:92
constexpr char ANCHOR
The tree is anchored.
Definition: Dopt_utils.hpp:94
void make_sorted_adjacency_list_rooted(const graphs::rooted_tree &t, std::vector< std::vector< node_size > > &L) noexcept
Make a sorted, rooted adjacency list sorted according to the sizes of the subtrees of the input roote...
Definition: Dopt_utils.hpp:115
constexpr char RIGHT_ANCHOR
The tree is right-anchored.
Definition: Dopt_utils.hpp:90
constexpr char LEFT_ANCHOR
The tree is left-anchored.
Definition: Dopt_utils.hpp:88
unsigned char place
Useful typedef to denote relative position.
Definition: Dopt_utils.hpp:72
void counting_sort(const value_iterator_t begin, const value_iterator_t end, const std::size_t largest_key_plus_1, const std::function< std::size_t(const value_t &)> &key, countingsort::memory< value_t > &mem) noexcept
Counting sort algorithm with reusable memory.
Definition: counting_sort.hpp:155
void get_size_subtrees(const tree_t &t, const node u, const node v, uint64_t *const sizes) noexcept
Calculate the size of every subtree of the tree t.
Definition: size_subtrees.hpp:74
Main namespace of the library.
Definition: basic_types.hpp:50
std::pair< node, node > edge
See Edge page for further details.
Definition: basic_types.hpp:58
uint64_t node
Node type. See Node / Vertex page for further details.
Definition: basic_types.hpp:53
Wrapper of a C array for autmatic deallocation of memory.
Definition: data_array.hpp:59
T * end() noexcept
Non-constant raw pointer to last+1 element.
Definition: data_array.hpp:293
T * begin() noexcept
Non-constant raw pointer to first element.
Definition: data_array.hpp:291
Struct used in many algorithms to sort edges according to some integer value.
Definition: pairs_utils.hpp:65
edge e
Edege.
Definition: pairs_utils.hpp:67
Memory used for the counting sort algorithm.
Definition: counting_sort.hpp:72
data_array< std::size_t > count
Amount of times the key of an element occurs.
Definition: counting_sort.hpp:74