LAL: Linear Arrangement Library 24.10.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
chunk.hpp
1/*********************************************************************
2 *
3 * Linear Arrangement Library - A library that implements a collection
4 * algorithms for linear arrangments of graphs.
5 *
6 * Copyright (C) 2019 - 2024
7 *
8 * This file is part of Linear Arrangement Library. The full code is available
9 * at:
10 * https://github.com/LAL-project/linear-arrangement-library.git
11 *
12 * Linear Arrangement Library is free software: you can redistribute it
13 * and/or modify it under the terms of the GNU Affero General Public License
14 * as published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * Linear Arrangement Library is distributed in the hope that it will be
18 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Affero General Public License for more details.
21 *
22 * You should have received a copy of the GNU Affero General Public License
23 * along with Linear Arrangement Library. If not, see <http://www.gnu.org/licenses/>.
24 *
25 * Contact:
26 *
27 * LluĂ­s Alemany Puig (lluis.alemany.puig@upc.edu)
28 * LQMC (Quantitative, Mathematical, and Computational Linguisitcs)
29 * CQL (Complexity and Quantitative Linguistics Lab)
30 * Jordi Girona St 1-3, Campus Nord UPC, 08034 Barcelona. CATALONIA, SPAIN
31 * Webpage: https://cqllab.upc.edu/people/lalemany/
32 *
33 * Ramon Ferrer i Cancho (rferrericancho@cs.upc.edu)
34 * LQMC (Quantitative, Mathematical, and Computational Linguisitcs)
35 * CQL (Complexity and Quantitative Linguistics Lab)
36 * Office 220, Omega building
37 * Jordi Girona St 1-3, Campus Nord UPC, 08034 Barcelona. CATALONIA, SPAIN
38 * Webpage: https://cqllab.upc.edu/people/rferrericancho/
39 *
40 ********************************************************************/
41
42#pragma once
43
44// C++ includes
45#if defined DEBUG
46#include <cassert>
47#endif
48#include <optional>
49#include <vector>
50
51// lal includes
52#include <lal/basic_types.hpp>
53#include <lal/detail/array.hpp>
54
55namespace lal {
56namespace linarr {
57
64class chunk {
65public:
67 typedef typename std::vector<node>::const_iterator const_iterator;
69 typedef typename std::vector<node>::iterator iterator;
70
71public:
72 /* MODIFIERS */
73
78 void add_node(const node u) noexcept {
79 m_nodes.push_back(u);
80 }
81
82 /* SETTERS */
83
88 void unset_parent_node() noexcept {
89 m_parent = {};
90 }
91
97 void set_parent_node(const node u) noexcept {
98 m_parent = u;
99 }
100
105 void unset_root_node() noexcept {
106 m_root = {};
107 }
108
114 void set_root_node(const node u) noexcept {
115 m_root = u;
116 }
117
118 /* GETTERS */
119
121 [[nodiscard]] bool has_parent_node() const noexcept
122 { return m_parent.has_value(); }
123
129 [[nodiscard]] node get_parent_node() const noexcept {
130#if defined DEBUG
131 assert(has_parent_node());
132#endif
133 return *m_parent;
134 }
135
137 [[nodiscard]] bool has_root_node() const noexcept { return m_root.has_value(); }
138
144 [[nodiscard]] node get_root_node() const noexcept {
145#if defined DEBUG
146 assert(has_root_node());
147#endif
148 return *m_root;
149 }
150
152 [[nodiscard]] const_iterator begin() const noexcept
153 { return m_nodes.begin(); }
155 [[nodiscard]] iterator begin() noexcept
156 { return m_nodes.begin(); }
157
159 [[nodiscard]] const_iterator end() const noexcept
160 { return m_nodes.end(); }
162 [[nodiscard]] iterator end() noexcept
163 { return m_nodes.end(); }
164
171 [[nodiscard]] const std::vector<node>& get_nodes() const noexcept
172 { return m_nodes; }
173
174private:
176 std::vector<node> m_nodes;
178 std::optional<node> m_parent;
180 std::optional<node> m_root;
181};
182
183} // -- namespace linarr
184} // -- namespace lal
Definition of a chunk.
Definition chunk.hpp:64
node get_root_node() const noexcept
Retrieve the root node of this chunk.
Definition chunk.hpp:144
std::vector< node > m_nodes
Collection of nodes in this chunk.
Definition chunk.hpp:176
void unset_parent_node() noexcept
Unsets the parent node of this chunk.
Definition chunk.hpp:88
std::vector< node >::iterator iterator
Useful typedef for non-constant iterators.
Definition chunk.hpp:69
node get_parent_node() const noexcept
Retrieve the parent node of this chunk.
Definition chunk.hpp:129
iterator begin() noexcept
A pointer to the beginning of the node sequence.
Definition chunk.hpp:155
std::optional< node > m_root
The root vertex of this chunk.
Definition chunk.hpp:180
const std::vector< node > & get_nodes() const noexcept
Collection of nodes of this chunk.
Definition chunk.hpp:171
void unset_root_node() noexcept
Unsets the root node of this chunk.
Definition chunk.hpp:105
std::vector< node >::const_iterator const_iterator
Useful typedef for constant iterators.
Definition chunk.hpp:67
void set_root_node(const node u) noexcept
Sets the root node of this chunk.
Definition chunk.hpp:114
bool has_root_node() const noexcept
Does this chunk have a parent node?
Definition chunk.hpp:137
std::optional< node > m_parent
The parent vertex of this chunk.
Definition chunk.hpp:178
bool has_parent_node() const noexcept
Does this chunk have a parent node?
Definition chunk.hpp:121
const_iterator begin() const noexcept
A pointer to the beginning of the node sequence.
Definition chunk.hpp:152
void set_parent_node(const node u) noexcept
Sets the parent node of this chunk.
Definition chunk.hpp:97
const_iterator end() const noexcept
A pointer to the ending of the node sequence.
Definition chunk.hpp:159
iterator end() noexcept
A pointer to the ending of the node sequence.
Definition chunk.hpp:162
void add_node(const node u) noexcept
Adds a new node to this chunk.
Definition chunk.hpp:78
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