LAL: Linear Arrangement Library 21.07.01
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
free_tree.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 - 2021
7 *
8 * This file is part of Linear Arrangement Library. To see the full code
9 * visit the webpage:
10 * https://github.com/lluisalemanypuig/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 (lalemany@cs.upc.edu)
28 * LARCA (Laboratory for Relational Algorithmics, Complexity and Learning)
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 * LARCA (Laboratory for Relational Algorithmics, Complexity and Learning)
35 * CQL (Complexity and Quantitative Linguistics Lab)
36 * Office S124, 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// lal includes
45#include <lal/graphs/undirected_graph.hpp>
46#include <lal/graphs/tree.hpp>
47
48namespace lal {
49namespace graphs {
50
59class free_tree : public undirected_graph, virtual public tree {
60public:
61 /* CONSTRUCTORS */
62
64 free_tree() noexcept : tree(), undirected_graph() { }
69 free_tree(uint32_t n) noexcept : undirected_graph(n) {
71 }
76 free_tree(const free_tree& t) noexcept : graph(), tree(), undirected_graph() {
78 }
79#ifndef SWIG
84 free_tree(free_tree&& t) noexcept {
85 move_full_free_tree(std::move(t));
86 }
87#endif
93 free_tree(const undirected_graph& t) noexcept;
94#ifndef SWIG
101
102#endif
104 virtual ~free_tree() noexcept { }
105
106 /* OPERATORS */
107
108#ifndef SWIG
113 free_tree& operator= (const free_tree& f) noexcept {
115 return *this;
116 }
122 move_full_free_tree(std::move(f));
123 return *this;
124 }
125#endif
126
127 /* MODIFIERS */
128
151 (node s, node t, bool norm = true, bool check_norm = true) noexcept;
152
166
173 void finish_bulk_add(bool norm = true, bool check = true) noexcept;
174
199 (const std::vector<edge>& edges, bool norm = true, bool check_norm = true)
200 noexcept;
201
229 (const std::vector<edge>& edges, bool norm = true, bool check_norm = true)
230 noexcept;
231
252 (node u, bool norm = true, bool check_norm = true)
253 noexcept;
254
266 void disjoint_union(const free_tree& t) noexcept;
267
268 void calculate_tree_type() noexcept;
269
270 /* GETTERS */
271
272 inline bool is_rooted() const noexcept { return false; }
273
313 head_vector get_head_vector(node r = 0) const noexcept;
314
315protected:
318 virtual void _init(uint32_t n) noexcept;
321 virtual void _clear() noexcept;
322
324 node u, node v,
325 uint32_t * const root_of,
326 uint32_t * const root_size
327 ) noexcept;
329 node u, node v,
330 uint32_t * const root_of,
331 uint32_t * const root_size
332 ) const noexcept;
334 node u, node v,
335 uint32_t * const root_of,
336 uint32_t * const root_size
337 ) noexcept;
339 node u, node v,
340 uint32_t * const root_of,
341 uint32_t * const root_size
342 ) const noexcept;
343
345 void copy_full_free_tree(const free_tree& f) noexcept;
347 void move_full_free_tree(free_tree&& f) noexcept;
348
349private:
351};
352
353} // -- namespace graphs
354} // -- namespace lal
Free tree graph class.
Definition free_tree.hpp:59
free_tree & add_edge(node s, node t, bool norm=true, bool check_norm=true) noexcept
Adds an edge to the tree.
void copy_full_free_tree(const free_tree &f) noexcept
Copies all members of this class and the parent class.
void calculate_tree_type() noexcept
Calculates the type of tree.
free_tree & add_edges(const std::vector< edge > &edges, bool norm=true, bool check_norm=true) noexcept
Adds a list of edges to the graph.
free_tree(free_tree &&t) noexcept
Move constructor.
Definition free_tree.hpp:84
free_tree & add_edge_bulk(node s, node t) noexcept
Adds an edge to the graph.
virtual free_tree & remove_edges_incident_to(node u, bool norm=true, bool check_norm=true) noexcept
Remove all edges incident to a given vertex.
free_tree & set_edges(const std::vector< edge > &edges, bool norm=true, bool check_norm=true) noexcept
Sets the edges to the graph.
free_tree(uint32_t n) noexcept
Constructor with number of vertices.
Definition free_tree.hpp:69
void move_full_free_tree(free_tree &&f) noexcept
Moves all members of this class and the parent class.
void call_union_find_after_add(node u, node v, uint32_t *const root_of, uint32_t *const root_size) noexcept
A call to the union find method.
head_vector get_head_vector(node r=0) const noexcept
Converts a free tree into a head vector.
free_tree(const undirected_graph &t) noexcept
Copy constructor with undirected graph.
void call_union_find_after_remove(node u, node v, uint32_t *const root_of, uint32_t *const root_size) noexcept
A call to the union find method.
void disjoint_union(const free_tree &t) noexcept
Disjoint union of trees.
virtual void _clear() noexcept
virtual void _init(uint32_t n) noexcept
free_tree(const free_tree &t) noexcept
Copy constructor.
Definition free_tree.hpp:76
void finish_bulk_add(bool norm=true, bool check=true) noexcept
Finishes adding edges in bulk.
free_tree & operator=(const free_tree &f) noexcept
Copy assignment operator.
Definition free_tree.hpp:113
virtual ~free_tree() noexcept
Destructor.
Definition free_tree.hpp:104
free_tree(undirected_graph &&t) noexcept
Move constructor with undirected graph.
bool is_rooted() const noexcept
Returns whether this tree is a rooted tree.
Definition free_tree.hpp:272
free_tree() noexcept
Empty constructor.
Definition free_tree.hpp:64
graph() noexcept
Empty constructor.
Definition graph.hpp:74
Tree graph class.
Definition tree.hpp:73
tree() noexcept
Empty constructor.
Definition tree.hpp:78
void tree_only_init(uint32_t n) noexcept
Initialises only the memory of class tree.
Undirected graph class.
Definition undirected_graph.hpp:67
undirected_graph() noexcept
Empty constructor.
Definition undirected_graph.hpp:72
Main namespace of the library.
Definition definitions.hpp:48
std::pair< node, node > edge
Edge type.
Definition definitions.hpp:75
uint32_t node
Node type.
Definition definitions.hpp:51
std::vector< uint32_t > head_vector
A head vector representation of a (usually) rooted tree.
Definition definitions.hpp:114