27 for (
I i{ size_t( 0 ) }; i <
size; ++i )
35 std::pair<I,bool>
unite(
I first,
I second )
37 auto firstRoot = updateRoot_( first );
38 auto secondRoot = updateRoot_( second );
39 if ( firstRoot == secondRoot )
40 return { firstRoot,
false };
42 if ( sizes_[firstRoot] < sizes_[secondRoot] )
44 roots_[firstRoot] = secondRoot;
45 sizes_[secondRoot] += sizes_[firstRoot];
46 return { secondRoot,
true };
50 roots_[secondRoot] = firstRoot;
51 sizes_[firstRoot] += sizes_[secondRoot];
52 return { firstRoot,
true };
59 auto firstRoot = updateRoot_( first );
60 auto secondRoot = updateRoot_( second );
61 return firstRoot == secondRoot;
67 return updateRoot_( a, findRootNoUpdate_( a ) );
73 return updateRootInRange_( a, findRootNoUpdate_( a ),
begin,
end );
79 for (
I i{ size_t( 0 ) }; i < roots_.
size(); ++i )
80 updateRoot_( i, findRootNoUpdate_( i ) );
92 I findRootNoUpdate_(
I a )
const
95 for (
I e = a; e != r; r = roots_[e = r] ) {}
99 I updateRoot_(
I a,
const I r )
105 std::swap( roots_[a], b );
111 I updateRoot_(
I a ) {
return updateRoot_( a, findRootNoUpdate_( a ) ); }
122 std::swap( roots_[a], b );
133 Vector<size_t, I> sizes_;
Simple union find data structure.
Definition MRUnionFind.h:16
std::pair< I, bool > unite(I first, I second)
Definition MRUnionFind.h:35
I find(I a)
finds the root of the set containing given element with optimizing data structure updates
Definition MRUnionFind.h:65
const Vector< I, I > & roots()
sets the root as the parent of each element, then returns the vector
Definition MRUnionFind.h:77
UnionFind(size_t size)
Definition MRUnionFind.h:19
void reset(size_t size)
reset roots to represent each element as disjoint set of rank 0
Definition MRUnionFind.h:23
size_t sizeOfComp(I a)
returns the size of component containing given element
Definition MRUnionFind.h:88
bool united(I first, I second)
returns true if given two elements are from one component
Definition MRUnionFind.h:57
auto size() const
Definition MRUnionFind.h:20
I findUpdateRange(I a, I begin, I end)
finds the root of the set containing given element with optimizing data structure in the range [begin...
Definition MRUnionFind.h:71
const Vector< I, I > & parents() const
gets the parents of all elements as in
Definition MRUnionFind.h:85
std::vector<T>-like container that requires specific indexing type,
Definition MRMesh/MRVector.h:20
void clear()
Definition MRMesh/MRVector.h:39
std::size_t size() const
Definition MRMesh/MRVector.h:42
void resize(size_t newSize) MR_REQUIRES_IF_SUPPORTED(sizeof(T)>0 &&std
Definition MRMesh/MRVector.h:44
void reserve(size_t capacity)
Definition MRMesh/MRVector.h:60
void push_back(const T &t)
Definition MRMesh/MRVector.h:111
auto begin(const BitSet &a)
Definition MRMesh/MRBitSet.h:280
auto end(const BitSet &)
Definition MRMesh/MRBitSet.h:282
Definition MRCameraOrientationPlugin.h:8
I
Definition MRMesh/MRMeshFwd.h:88