62#ifndef __ADS_UnionFind
63 #define __ADS_UnionFind
108 class Policy = NoObservers >
130 template<
class... O >
131 requires(
sizeof...( O ) > 0 )
140 [[nodiscard]]
int n(
void )
const {
return(
int( f_p.size() ) ); }
143 [[nodiscard]]
int count(
void )
const {
return( f_count ); }
206 requires( Subject::dynamic )
208 return( f_sub.attach( o ) );
214 requires( Subject::dynamic )
223 void link(
int x ,
int y );
226 void linkTold(
int x ,
int y );
229 ADS_COLD_PATH void linkCold(
int x ,
int y ) { linkTold( x , y ); }
233 [[nodiscard]]
bool forest(
void )
const;
235 std::vector< int > f_p;
252#include "ADS/mfset/impl/UnionFind.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The typed modifications, beyond the book: the vocabulary by which a structure tells the observers att...
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
the union of disjoint sets of , the roots joined by L, the paths shortened by C, the links of the roo...
Definition UnionFind.h:110
void reset(int n)
back to the components
int find(int x)
the representative of the component of
DisjointSets(int n, O &... o)
the components , the static observers o...
int count(void) const
the number of components
Definition UnionFind.h:143
DisjointSets(int n=0)
the components
typename Policy::template bind< modifications, DisjointSets > Subject
the subject
Definition UnionFind.h:120
const Subject & subject(void) const
the subject
Definition UnionFind.h:200
int attach(O &o)
attaches the observer and gives its number
Definition UnionFind.h:205
bool same(int x, int y)
whether and are in the same component
int size(int x)
the number of elements of the component of
Subject & subject(void)
the subject, for ADS::batch() and ADS::quiet()
Definition UnionFind.h:198
void detach(int id)
detaches the observer number
Definition UnionFind.h:213
mod::Changed< mod::Parent, int, int > Linked
the link of a root under another root: the parent of the handle from to the other root
Definition UnionFind.h:116
mod::list< Linked, mod::Rebuilt > modifications
the events: a root linked under another, the forest made anew
Definition UnionFind.h:118
bool merge(int x, int y)
joins the components of and , the smaller (of lower rank) under the larger, under the root of if th...
int n(void) const
the number of elements
Definition UnionFind.h:140
#define ADS_COLD_PATH
a function of a rare path: never inlined, laid out away from the hot code
Definition Portable.h:107
#define ADS_NO_UNIQUE_ADDRESS
an empty member that takes no storage, by the attribute that does so (the standard one is accepted bu...
Definition Portable.h:81
Union
how the roots of two trees are joined: the smaller tree under the root of the larger,...
Definition UnionFind.h:92
DisjointSets<> UnionFind
the union by size with path halving
Definition UnionFind.h:242
Compression
how find() shortens the path: halving it (every other node on the way made a child of its grandparent...
Definition UnionFind.h:100
@ RANK
the lower rank under the higher
Definition UnionFind.h:94
@ SIZE
the smaller tree under the root of the larger
Definition UnionFind.h:93
@ FULL
each node under the root
Definition UnionFind.h:102
@ HALVING
half the path under grandparents
Definition UnionFind.h:101
the attribute A of the item of handle changed from from to to
Definition Modification.h:600
a list of types, the events of a structure [see Modification.h]
Definition Modification.h:482