LAL: Linear Arrangement Library 24.10.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
chunk_sequence.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
49// lal includes
50#include <lal/basic_types.hpp>
51#include <lal/linarr/chunking/chunk.hpp>
52#include <lal/detail/array.hpp>
53
54namespace lal {
55namespace linarr {
56
108public:
110 typedef typename std::vector<chunk>::const_iterator const_iterator;
112 typedef typename std::vector<chunk>::iterator iterator;
113
114public:
115
121 void init(const std::size_t n) noexcept {
123 }
124
130 [[nodiscard]] const chunk& operator[] (const std::size_t i) const noexcept {
131#if defined DEBUG
132 assert(i < size());
133#endif
134 return m_chunks[i];
135 }
136
142 [[nodiscard]] chunk& operator[] (const std::size_t i) noexcept {
143#if defined DEBUG
144 assert(i < size());
145#endif
146 return m_chunks[i];
147 }
148
149 /* MODIFIERS */
150
155 void push_chunk() noexcept {
156 m_chunks.push_back({});
157 }
158
164 void push_chunk(const node u) noexcept {
165 push_chunk();
166 m_chunks.back().add_node(u);
167 }
168
169 /* SETTERS */
170
171 void set_chunk_index(const node u, const std::size_t i) noexcept {
172#if defined DEBUG
173 assert(u < m_from_node_to_chunk.size());
174#endif
176 }
177
178 /* GETTERS */
179
181 [[nodiscard]] std::size_t size() const noexcept {
182 return m_chunks.size();
183 }
184
186 [[nodiscard]] std::size_t get_chunk_index(const node u) const noexcept {
187#if defined DEBUG
188 assert(u < m_from_node_to_chunk.size());
189#endif
190 return m_from_node_to_chunk[u];
191 }
192
194 [[nodiscard]] const_iterator begin() const noexcept
195 { return m_chunks.begin(); }
197 [[nodiscard]] iterator begin() noexcept
198 { return m_chunks.begin(); }
199
201 [[nodiscard]] const_iterator end() const noexcept
202 { return m_chunks.end(); }
204 [[nodiscard]] iterator end() noexcept
205 { return m_chunks.end(); }
206
213 [[nodiscard]] const std::vector<chunk>& get_chunks() const noexcept
214 { return m_chunks; }
215
216private:
218 std::vector<chunk> m_chunks;
221};
222
223} // -- namespace linarr
224} // -- namespace lal
Chunk sequence of a syntactic dependency tree.
Definition chunk_sequence.hpp:107
const_iterator begin() const noexcept
A pointer to the beginning of the chunk sequence.
Definition chunk_sequence.hpp:194
void push_chunk() noexcept
Adds a new chunk to the collection.
Definition chunk_sequence.hpp:155
std::vector< chunk >::const_iterator const_iterator
Useful typedef for constant iterators.
Definition chunk_sequence.hpp:110
const chunk & operator[](const std::size_t i) const noexcept
The i-th chunk.
Definition chunk_sequence.hpp:130
void push_chunk(const node u) noexcept
Adds a new chunk to the collection.
Definition chunk_sequence.hpp:164
detail::array< std::size_t > m_from_node_to_chunk
Index of every.
Definition chunk_sequence.hpp:220
const std::vector< chunk > & get_chunks() const noexcept
The sequence of chunks.
Definition chunk_sequence.hpp:213
std::size_t get_chunk_index(const node u) const noexcept
Returns the chunk index of node u.
Definition chunk_sequence.hpp:186
std::size_t size() const noexcept
Returns the number of chunks.
Definition chunk_sequence.hpp:181
std::vector< chunk > m_chunks
The sequence of chunks.
Definition chunk_sequence.hpp:218
const_iterator end() const noexcept
A pointer to the ending of the chunk sequence.
Definition chunk_sequence.hpp:201
iterator end() noexcept
A pointer to the ending of the chunk sequence.
Definition chunk_sequence.hpp:204
void init(const std::size_t n) noexcept
Initializes this chunk sequence.
Definition chunk_sequence.hpp:121
iterator begin() noexcept
A pointer to the beginning of the chunk sequence.
Definition chunk_sequence.hpp:197
std::vector< chunk >::iterator iterator
Useful typedef for non-constant iterators.
Definition chunk_sequence.hpp:112
Definition of a chunk.
Definition chunk.hpp:64
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
std::size_t size() const noexcept
Size of the array.
Definition array.hpp:215
void resize(const std::size_t new_size) noexcept
Resize the array.
Definition array.hpp:187