LAL: Linear Arrangement Library 23.01.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
basic_types.hpp
1
2
3/*********************************************************************
4 *
5 * Linear Arrangement Library - A library that implements a collection
6 * algorithms for linear arrangments of graphs.
7 *
8 * Copyright (C) 2019 - 2023
9 *
10 * This file is part of Linear Arrangement Library. The full code is available
11 * at:
12 * https://github.com/LAL-project/linear-arrangement-library.git
13 *
14 * Linear Arrangement Library is free software: you can redistribute it
15 * and/or modify it under the terms of the GNU Affero General Public License
16 * as published by the Free Software Foundation, either version 3 of the
17 * License, or (at your option) any later version.
18 *
19 * Linear Arrangement Library is distributed in the hope that it will be
20 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Affero General Public License for more details.
23 *
24 * You should have received a copy of the GNU Affero General Public License
25 * along with Linear Arrangement Library. If not, see <http://www.gnu.org/licenses/>.
26 *
27 * Contact:
28 *
29 * LluĂ­s Alemany Puig (lalemany@cs.upc.edu)
30 * LARCA (Laboratory for Relational Algorithmics, Complexity and Learning)
31 * CQL (Complexity and Quantitative Linguistics Lab)
32 * Jordi Girona St 1-3, Campus Nord UPC, 08034 Barcelona. CATALONIA, SPAIN
33 * Webpage: https://cqllab.upc.edu/people/lalemany/
34 *
35 * Ramon Ferrer i Cancho (rferrericancho@cs.upc.edu)
36 * LARCA (Laboratory for Relational Algorithmics, Complexity and Learning)
37 * CQL (Complexity and Quantitative Linguistics Lab)
38 * Office S124, Omega building
39 * Jordi Girona St 1-3, Campus Nord UPC, 08034 Barcelona. CATALONIA, SPAIN
40 * Webpage: https://cqllab.upc.edu/people/rferrericancho/
41 *
42 ********************************************************************/
43
44#pragma once
45
46// C++ includes
47#include <cinttypes>
48#include <vector>
49
50namespace lal {
51
53typedef uint64_t node;
55typedef uint64_t position;
56
58typedef std::pair<node, node> edge;
60typedef std::pair<edge,edge> edge_pair;
62typedef std::vector<node> neighbourhood;
64typedef std::vector<uint64_t> head_vector;
65
67struct node_t {
68 uint64_t value;
69
70 // CONSTRUCTORS
71
72 node_t() = default;
73
74 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
75 node_t(const T& _v) noexcept : value(_v) { }
76
77 // -- ASSIGNMENT OPERATORS --
78
79 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
80 node_t& operator= (const T& _v) noexcept { value = _v; return *this; }
81
82 // -- COMPARISONS --
83
84 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
85 bool operator== (const T& t) const noexcept { return value == t; }
86 bool operator== (const node_t& u) const noexcept { return value == u.value; }
87 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
88 friend bool operator== (const T& t, const node_t& u) noexcept { return u.value == t; }
89
90 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
91 bool operator!= (const T& t) const noexcept { return value != t; }
92 bool operator!= (const node_t& u) const noexcept { return value != u.value; }
93 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
94 friend bool operator!= (const T& t, const node_t& u) noexcept { return u.value != t; }
95
96 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
97 bool operator< (const T& t) const noexcept { return value < t; }
98 bool operator< (const node_t& u) const noexcept { return value < u.value; }
99 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
100 friend bool operator< (const T& t, const node_t& u) noexcept { return t < u.value; }
101
102 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
103 bool operator<= (const T& t) const noexcept { return value <= t; }
104 bool operator<= (const node_t& u) const noexcept { return value <= u.value; }
105 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
106 friend bool operator<= (const T& t, const node_t& u) noexcept { return t <= u.value; }
107
108 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
109 bool operator> (const T& t) const noexcept { return value > t; }
110 bool operator> (const node_t& u) const noexcept { return value > u.value; }
111 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
112 friend bool operator> (const T& t, const node_t& u) noexcept { return t > u.value; }
113
114 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
115 bool operator>= (const T& t) const noexcept { return value >= t; }
116 bool operator>= (const node_t& u) const noexcept { return value >= u.value; }
117 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
118 friend bool operator>= (const T& t, const node_t& u) noexcept { return t >= u.value; }
119
120 // -- ARITHMETIC --
121
122 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
123 node_t operator+ (const T& t) const noexcept { return node_t{value + t}; }
124 node_t operator+ (const node_t& u) const noexcept { return node_t{value + u.value}; }
125 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
126 friend node_t operator+ (const T& t, const node_t& u) noexcept { return node_t{u.value + t}; }
127
128 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
129 node_t& operator+= (const T& t) noexcept { value += t; return *this; }
130 node_t& operator+= (const node_t& u) noexcept { value += u.value; return *this; }
131
132 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
133 node_t operator- (const T& t) const noexcept { return node_t{value - t}; }
134 node_t operator- (const node_t& u) const noexcept { return node_t{value - u.value}; }
135 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
136 friend node_t operator- (const T& t, const node_t& u) noexcept { return node_t{t - u.value}; }
137
138 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
139 node_t& operator-= (const T& t) noexcept { value -= t; return *this; }
140 node_t& operator-= (const node_t& u) noexcept { value -= u.value; return *this; }
141
142 node_t& operator++() noexcept { ++value; return *this; }
143 node_t& operator--() noexcept { --value; return *this; }
144
145 // input/output operators
146
147 template <class stream>
148 friend stream& operator>> (stream& s, node_t& p) noexcept {
149 s >> p.value;
150 return s;
151 }
152
153 template <class stream>
154 friend stream& operator<< (stream& s, const node_t& p) noexcept {
155 s << p.value;
156 return s;
157 }
158
159 uint64_t operator*() const noexcept { return value; }
160};
161
163typedef std::pair<node_t, node_t> edge_t;
165typedef std::pair<edge_t, edge_t> edge_pair_t;
166
169 uint64_t value;
170
171 // CONSTRUCTORS
172
173 position_t() = default;
174
175 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
176 position_t(const T& _v) noexcept : value(_v) { }
177
178 // -- ASSIGNMENT OPERATORS --
179
180 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
181 position_t& operator= (const T& _v) noexcept { value = _v; return *this; }
182
183 // -- COMPARISONS --
184
185 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
186 bool operator== (const T& t) const noexcept { return value == t; }
187 bool operator== (const position_t& u) const noexcept { return value == u.value; }
188 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
189 friend bool operator== (const T& t, const position_t& u) noexcept { return u.value == t; }
190
191 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
192 bool operator!= (const T& t) const noexcept { return value != t; }
193 bool operator!= (const position_t& u) const noexcept { return value != u.value; }
194 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
195 friend bool operator!= (const T& t, const position_t& u) noexcept { return u.value != t; }
196
197 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
198 bool operator< (const T& t) const noexcept { return value < t; }
199 bool operator< (const position_t& u) const noexcept { return value < u.value; }
200 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
201 friend bool operator< (const T& t, const position_t& u) noexcept { return t < u.value; }
202
203 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
204 bool operator<= (const T& t) const noexcept { return value <= t; }
205 bool operator<= (const position_t& u) const noexcept { return value <= u.value; }
206 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
207 friend bool operator<= (const T& t, const position_t& u) noexcept { return t <= u.value; }
208
209 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
210 bool operator> (const T& t) const noexcept { return value > t; }
211 bool operator> (const position_t& u) const noexcept { return value > u.value; }
212 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
213 friend bool operator> (const T& t, const position_t& u) noexcept { return t > u.value; }
214
215 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
216 bool operator>= (const T& t) const noexcept { return value >= t; }
217 bool operator>= (const position_t& u) const noexcept { return value >= u.value; }
218 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
219 friend bool operator>= (const T& t, const position_t& u) noexcept { return t >= u.value; }
220
221 // -- ARITHMETIC --
222
223 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
224 position_t operator+ (const T& t) const noexcept { return position_t{value + t}; }
225 position_t operator+ (const position_t& u) const noexcept { return position_t{value + u.value}; }
226 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
227 friend position_t operator+ (const T& t, const position_t& u) noexcept { return position_t{u.value + t}; }
228
229 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
230 position_t& operator+= (const T& t) noexcept { value += t; return *this; }
231 position_t& operator+= (const position_t& u) noexcept { value += u.value; return *this; }
232
233 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
234 position_t operator- (const T& t) const noexcept { return position_t{value - t}; }
235 position_t operator- (const position_t& u) const noexcept { return position_t{value - u.value}; }
236 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
237 friend position_t operator- (const T& t, const position_t& u) noexcept { return position_t{t - u.value}; }
238
239 template <typename T,std::enable_if_t<std::is_integral_v<T>, bool> = true>
240 position_t& operator-= (const T& t) noexcept { value -= t; return *this; }
241 position_t& operator-= (const position_t& u) noexcept { value -= u.value; return *this; }
242
243 position_t& operator++() noexcept { ++value; return *this; }
244 position_t& operator--() noexcept { --value; return *this; }
245
246 // input/output operators
247
248 template <class stream>
249 friend stream& operator>> (stream& s, position_t& p) noexcept {
250 s >> p.value;
251 return s;
252 }
253
254 template <class stream>
255 friend stream& operator<< (stream& s, const position_t& p) noexcept {
256 s << p.value;
257 return s;
258 }
259
260 uint64_t operator*() const noexcept { return value; }
261};
262
263static_assert( std::is_trivial_v<node_t>);
264static_assert( std::is_trivially_constructible_v<node_t>);
265static_assert( std::is_trivially_copy_assignable_v<node_t>);
266static_assert( std::is_trivially_copy_constructible_v<node_t>);
267static_assert( std::is_trivially_copyable_v<node_t>);
268static_assert( std::is_trivially_move_constructible_v<node_t>);
269static_assert( std::is_trivially_move_assignable_v<node_t>);
270static_assert( std::is_constructible_v<node_t, node_t>);
271static_assert( std::is_constructible_v<node_t, node>);
272static_assert( std::is_constructible_v<node_t, int>);
273static_assert( std::is_trivially_assignable_v<node_t, node_t>);
274static_assert(not std::is_trivially_assignable_v<node_t, node>);
275static_assert(not std::is_trivially_assignable_v<node_t, int>);
276static_assert( std::is_trivially_destructible_v<node_t>);
277
278static_assert( std::is_trivial_v<position_t>);
279static_assert( std::is_trivially_constructible_v<position_t>);
280static_assert( std::is_trivially_copy_assignable_v<position_t>);
281static_assert( std::is_trivially_copy_constructible_v<position_t>);
282static_assert( std::is_trivially_copyable_v<position_t>);
283static_assert( std::is_trivially_move_constructible_v<position_t>);
284static_assert( std::is_trivially_move_assignable_v<position_t>);
285static_assert( std::is_constructible_v<position_t, position_t>);
286static_assert( std::is_constructible_v<position_t, position>);
287static_assert( std::is_constructible_v<position_t, int>);
288static_assert( std::is_trivially_assignable_v<position_t, position_t>);
289static_assert(not std::is_trivially_assignable_v<position_t, position>);
290static_assert(not std::is_trivially_assignable_v<position_t, int>);
291static_assert( std::is_trivially_destructible_v<position_t>);
292
293} // -- namespace lal
Main namespace of the library.
Definition: basic_types.hpp:50
std::pair< edge, edge > edge_pair
Edge pair type.
Definition: basic_types.hpp:60
std::vector< uint64_t > head_vector
See Head vector page for further details.
Definition: basic_types.hpp:64
std::pair< node, node > edge
See Edge page for further details.
Definition: basic_types.hpp:58
uint64_t position
Node's position type.
Definition: basic_types.hpp:55
std::pair< edge_t, edge_t > edge_pair_t
Similar to edge_pair.
Definition: basic_types.hpp:165
uint64_t node
Node type. See Node / Vertex page for further details.
Definition: basic_types.hpp:53
std::vector< node > neighbourhood
List of nodes.
Definition: basic_types.hpp:62
std::pair< node_t, node_t > edge_t
Similar to edge.
Definition: basic_types.hpp:163
Typesafe node type.
Definition: basic_types.hpp:67
Typesafe position type.
Definition: basic_types.hpp:168