51#include <lal/basic_types.hpp>
52#include <lal/detail/data_array.hpp>
134 from_data<true>(dir_arr.begin(), dir_arr.end());
156 m_n = dir_arr.size();
160 from_data<true>(dir_arr.begin(), dir_arr.end());
166 :
m_memory(std::move(arr.m_memory)),
173 arr.m_direct =
nullptr;
174 arr.m_inverse =
nullptr;
185 arr.m_direct =
nullptr;
186 arr.m_inverse =
nullptr;
213 template <
typename It>
215 return from_direct(begin, end, std::distance(begin, end));
227 template <
typename It>
253 template <
typename It>
255 return from_inverse(begin, end, std::distance(begin, end));
267 template <
typename It>
277 if (
size() != arr.size()) {
return size() < arr.size(); }
279 for (std::size_t i = 0; i <
size() - 1; ++i) {
280 if (
m_direct[i] != arr.m_direct[i]) {
281 return m_direct[i] < arr.m_direct[i];
333 typename NODE,
typename POSITION,
335 (std::is_integral_v<NODE> or std::is_same_v<NODE, node_t>)
337 (std::is_integral_v<POSITION> or std::is_same_v<POSITION, position_t>)
341 void assign(
const NODE u,
const POSITION p)
noexcept {
346 if constexpr (std::is_same_v<NODE, node_t> and std::is_same_v<POSITION, position_t>) {
350 else if constexpr (std::is_same_v<NODE, node_t>) {
354 else if constexpr (std::is_same_v<POSITION, position_t>) {
379 std::is_same_v<what, node_t> or std::is_same_v<what, position_t>
383 void swap(
const what u_t,
const what v_t)
noexcept {
384 if constexpr (std::is_same_v<what, node_t>) {
438 std::size_t
size() const noexcept {
return m_n; }
453 for (std::size_t i = 0; i <
m_n; ++i) {
assign(i,i); }
475 for (
node u = 0; u <
m_n; ++u) {
524 template <
bool from_direct_arr,
typename It>
532 if constexpr (from_direct_arr) {
533 for (It it = begin; it != end; ++it, ++i) {
539 for (It it = begin; it != end; ++it, ++i) {
Linear arrangement of vertices.
Definition: linear_arrangement.hpp:103
std::vector< position > direct_as_vector() const noexcept
Constructs a std::vector from the direct arrangement.
Definition: linear_arrangement.hpp:499
std::size_t m_n
Size of the arrangement (number of nodes in the arrangement).
Definition: linear_arrangement.hpp:551
void swap(const what u_t, const what v_t) noexcept
Swaps the position of two vertices or of two positions.
Definition: linear_arrangement.hpp:383
node * m_inverse
Pointer to the inverse arrangement values.
Definition: linear_arrangement.hpp:556
position get_position_of(const node u) const noexcept
Returns the position of node u.
Definition: linear_arrangement.hpp:304
void clear() noexcept
Frees the memory used by the linear arrangement.
Definition: linear_arrangement.hpp:296
void mirror() noexcept
Mirror the arrangement.
Definition: linear_arrangement.hpp:431
node operator[](const node_t &u) const noexcept
Access to linear arrangement using a type-safe node.
Definition: linear_arrangement.hpp:288
void from_data(const It begin, const It end) noexcept
Initializes this arrangement from a direct or inverse arrangement.
Definition: linear_arrangement.hpp:525
std::vector< node > inverse_as_vector() const noexcept
Constructs a std::vector from the inverse arrangement.
Definition: linear_arrangement.hpp:503
std::size_t size() const noexcept
Size of the arrangement (number of nodes in the arrangement).
Definition: linear_arrangement.hpp:438
linear_arrangement & operator=(const linear_arrangement &arr) noexcept
Copy assignment operator.
Definition: linear_arrangement.hpp:145
linear_arrangement(linear_arrangement &&arr) noexcept
Move constructor.
Definition: linear_arrangement.hpp:165
static linear_arrangement from_inverse(const std::vector< node > &v) noexcept
Construct a linear arrangement from an inverse arrangement.
Definition: linear_arrangement.hpp:240
void assign(const NODE u, const POSITION p) noexcept
Assigns a node u to position p.
Definition: linear_arrangement.hpp:341
static linear_arrangement identity(std::size_t n) noexcept
Constructs a linear arrangement from an inverse arrangement.
Definition: linear_arrangement.hpp:444
detail::data_array< uint64_t > m_memory
Definition: linear_arrangement.hpp:549
const node * begin_direct() const noexcept
Pointer to beginning of direct arrangement.
Definition: linear_arrangement.hpp:483
linear_arrangement(const std::vector< position > &dir_arr) noexcept
Constructor with direct arrangement.
Definition: linear_arrangement.hpp:127
static linear_arrangement from_inverse(It begin, It end) noexcept
Construct a linear arrangement from an inverse arrangement.
Definition: linear_arrangement.hpp:254
void update_inverse() noexcept
Updates the inverse arrangement using the direct arrangement.
Definition: linear_arrangement.hpp:474
void resize(std::size_t n) noexcept
Changes the size of the arrangement.
Definition: linear_arrangement.hpp:317
static linear_arrangement from_direct(It begin, It end) noexcept
Construct a linear arrangement from a direct arrangement.
Definition: linear_arrangement.hpp:214
static linear_arrangement from_direct(const std::vector< position > &v) noexcept
Construct a linear arrangement from a direct arrangement.
Definition: linear_arrangement.hpp:200
void shift_right() noexcept
Shifts the vertices one position to the right.
Definition: linear_arrangement.hpp:413
node * end_inverse() noexcept
Pointer to end of inverse arrangement.
Definition: linear_arrangement.hpp:494
node get_node_at(const position p) const noexcept
Returns the node at position p.
Definition: linear_arrangement.hpp:308
static linear_arrangement from_direct(It begin, It end, std::size_t size) noexcept
Construct a linear arrangement from a direct arrangement.
Definition: linear_arrangement.hpp:228
void identity() noexcept
Makes this arrangement an identity arrangement.
Definition: linear_arrangement.hpp:452
virtual ~linear_arrangement() noexcept=default
Default destructor.
const node * begin_inverse() const noexcept
Pointer to beginning of inverse arrangement.
Definition: linear_arrangement.hpp:492
bool operator<(const linear_arrangement &arr) const noexcept
Lexicographic comparison of two linear arrangements.
Definition: linear_arrangement.hpp:276
linear_arrangement(const linear_arrangement &arr) noexcept
Copy constructor.
Definition: linear_arrangement.hpp:138
node * begin_inverse() noexcept
Pointer to beginning of inverse arrangement.
Definition: linear_arrangement.hpp:490
linear_arrangement() noexcept=default
Default constructor.
static linear_arrangement from_inverse(It begin, It end, std::size_t size) noexcept
Construct a linear arrangement from an inverse arrangement.
Definition: linear_arrangement.hpp:268
const node * end_inverse() const noexcept
Pointer to end of inverse arrangement.
Definition: linear_arrangement.hpp:496
void shift_left() noexcept
Shifts the vertices one position to the left.
Definition: linear_arrangement.hpp:401
void set_pointers() noexcept
Definition: linear_arrangement.hpp:510
position * m_direct
Pointer to the direct arrangement values.
Definition: linear_arrangement.hpp:554
node * begin_direct() noexcept
Pointer to beginning of direct arrangement.
Definition: linear_arrangement.hpp:481
const node * end_direct() const noexcept
Pointer to end of direct arrangement.
Definition: linear_arrangement.hpp:487
void update_direct() noexcept
Updates the direct arrangement using the inverse arrangement.
Definition: linear_arrangement.hpp:462
node * end_direct() noexcept
Pointer to end of direct arrangement.
Definition: linear_arrangement.hpp:485
Main namespace of the library.
Definition: basic_types.hpp:50
uint64_t position
Node's position type.
Definition: basic_types.hpp:55
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
void resize(std::size_t new_size) noexcept
Resize the array.
Definition: data_array.hpp:175
void clear() noexcept
Clear the contents of the array.
Definition: data_array.hpp:162
T * begin() noexcept
Non-constant raw pointer to first element.
Definition: data_array.hpp:291
Typesafe node type.
Definition: basic_types.hpp:67
Typesafe position type.
Definition: basic_types.hpp:168