ADS
Algorithms and Data Structures
Toggle main menu visibility
Loading...
Searching...
No Matches
MFSet.h
Go to the documentation of this file.
1
/*--------------------------------------------------------------------------*/
2
/*------------------------------ File MFSet.h ------------------------------*/
3
/*--------------------------------------------------------------------------*/
71
/*--------------------------------------------------------------------------*/
72
/*----------------------------- DEFINITIONS --------------------------------*/
73
/*--------------------------------------------------------------------------*/
74
75
#ifndef __ADS_MFSet
76
#define __ADS_MFSet
77
/* self-identification: #endif constant */
78
79
/*--------------------------------------------------------------------------*/
80
/*------------------------------ INCLUDES ----------------------------------*/
81
/*--------------------------------------------------------------------------*/
82
83
#include "
ADS/Contract.h
"
84
#include "
ADS/graph/Graph.h
"
85
86
#include <stdexcept>
87
#include <utility>
88
#include <vector>
89
90
/*--------------------------------------------------------------------------*/
91
/*--------------------------- NAMESPACE ------------------------------------*/
92
/*--------------------------------------------------------------------------*/
93
94
namespace
ADS
95
{
96
97
/*--------------------------------------------------------------------------*/
98
/*------------------------------ CLASS MFSet -------------------------------*/
99
/*--------------------------------------------------------------------------*/
100
102
class
MFSet
103
{
104
105
/*--------------------------------------------------------------------------*/
106
public
:
108
enum class
Union
{
109
NONE
,
110
RANK
,
111
SIZE
112
};
113
118
explicit
MFSet
(
int
n
,
Union
u =
Union::RANK
,
bool
compress =
true
);
119
121
[[nodiscard]]
int
n
(
void
)
const
;
122
124
[[nodiscard]]
int
count
(
void
)
const
;
125
144
int
find
(
int
x );
145
171
bool
merge
(
int
x ,
int
y );
172
176
bool
same
(
int
x ,
int
y );
177
180
[[nodiscard]]
int
parent
(
int
x )
const
;
181
184
[[nodiscard]]
int
rank
(
int
x )
const
;
185
189
[[nodiscard]]
int
size
(
int
x )
const
;
190
192
[[nodiscard]]
long
steps
(
void
)
const
;
193
194
/*--------------------------------------------------------------------------*/
195
private
:
197
[[nodiscard]]
int
root(
int
x )
const
;
198
201
[[nodiscard]]
bool
forest(
void
)
const
;
202
203
std::vector< int > f_p;
204
std::vector< int > f_rank;
205
std::vector< int > f_size;
206
Union
f_union;
207
bool
f_compress;
208
int
f_count;
209
long
f_steps = 0;
210
211
};
// end( class MFSet )
212
213
/*--------------------------------------------------------------------------*/
214
232
template
< Graph G >
233
MFSet
components
(
const
G & g );
234
235
/*--------------------------------------------------------------------------*/
236
237
}
// end( namespace ADS )
238
239
/*--------------------------------------------------------------------------*/
240
/*-------------------------- IMPLEMENTATION --------------------------------*/
241
/*--------------------------------------------------------------------------*/
242
243
#include "ADS/mfset/impl/MFSet.tpp"
244
245
/*--------------------------------------------------------------------------*/
246
247
#endif
/* MFSet.h included */
248
249
/*--------------------------------------------------------------------------*/
250
/*---------------------------- End File MFSet.h ----------------------------*/
251
/*--------------------------------------------------------------------------*/
Contract.h
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
ADS::MFSet
the union of disjoint sets on a forest
Definition
MFSet.h:103
ADS::MFSet::rank
int rank(int x) const
the rank of
ADS::MFSet::find
int find(int x)
the representative of the component of , the root of its tree
ADS::MFSet::Union
Union
how merge() chooses the root that goes under the other one
Definition
MFSet.h:108
ADS::MFSet::Union::RANK
@ RANK
the lower tree under the higher one
Definition
MFSet.h:110
ADS::MFSet::Union::SIZE
@ SIZE
the smaller tree under the larger one
Definition
MFSet.h:111
ADS::MFSet::Union::NONE
@ NONE
the root of under that of
Definition
MFSet.h:109
ADS::MFSet::n
int n(void) const
the number of elements
ADS::MFSet::merge
bool merge(int x, int y)
joins the components of and ; true if they were distinct
ADS::MFSet::same
bool same(int x, int y)
true if and are in the same component, find( x ) == find( y )
ADS::MFSet::size
int size(int x) const
the number of nodes of the tree of , if is a root and the union is by size
ADS::MFSet::parent
int parent(int x) const
the parent of , itself if a root
ADS::MFSet::MFSet
MFSet(int n, Union u=Union::RANK, bool compress=true)
the components (the Mfset( n ) of the book), with the given union and with the compression of the p...
ADS::MFSet::steps
long steps(void) const
the steps up the trees made by find() so far
ADS::MFSet::count
int count(void) const
the number of components
Graph.h
The GRAPH of chapter 9 and its realizations.
ADS::components
MFSet components(const G &g)
the MFSET of the connected components of an unoriented graph, built by merging the ends of each edge ...
ADS
Definition
ADT.h:96
ADS
mfset
MFSet.h
Generated by
1.17.0