43 for (
I i{ size_t( 0 ) }; i <
size; ++i )
55 if ( firstRoot == secondRoot )
56 return { firstRoot,
false };
58 return { secondRoot,
true };
85 for (
I i{ size_t( 0 ) }; i <
parents_.size(); ++i )
98 for (
I e = a; e != r; r =
parents_[e = r] ) {}
167 for (
I i{ size_t( 0 ) }; i < this->
parents_.size(); ++i )
176 sizes_.resize(
size, 1 );
185 if ( firstRoot == secondRoot )
186 return { firstRoot,
false };
188 if ( sizes_[firstRoot] < sizes_[secondRoot] )
190 this->
parents_[firstRoot] = secondRoot;
191 sizes_[secondRoot] += sizes_[firstRoot];
192 return { secondRoot,
true };
196 this->
parents_[secondRoot] = firstRoot;
197 sizes_[firstRoot] += sizes_[secondRoot];
198 return { firstRoot,
true };
232 first = findAtomic_( first );
233 second = findAtomic_( second );
234 if ( first == second )
237 if ( first < second )
238 std::swap( first, second );
240 if ( casStrong_( this->
parents_[first], first, second ) )
252 static I loadAtomic_(
I& slot )
254#ifdef __cpp_lib_atomic_ref
255 return I( std::atomic_ref<typename I::ValueType>( slot.get() ).load( std::memory_order_relaxed ) );
257 return I( __atomic_load_n( &slot.get(), __ATOMIC_RELAXED ) );
262 static void casWeak_(
I& slot,
I expected,
I desired )
264 using T =
typename I::ValueType;
265 T exp = expected.get();
266#ifdef __cpp_lib_atomic_ref
267 std::atomic_ref<T>( slot.get() ).compare_exchange_weak( exp, desired.get(), std::memory_order_relaxed );
269 __atomic_compare_exchange_n( &slot.get(), &exp, desired.get(),
true, __ATOMIC_RELAXED, __ATOMIC_RELAXED );
274 static bool casStrong_(
I& slot,
I expected,
I desired )
276 using T =
typename I::ValueType;
277 T exp = expected.get();
278#ifdef __cpp_lib_atomic_ref
279 return std::atomic_ref<T>( slot.get() ).compare_exchange_strong( exp, desired.get(), std::memory_order_acq_rel, std::memory_order_relaxed );
281 return __atomic_compare_exchange_n( &slot.get(), &exp, desired.get(),
false, __ATOMIC_ACQ_REL, __ATOMIC_RELAXED );
297 casWeak_( this->
parents_[a], p, gp );
312 for (
auto f : region )
314 auto& uniqIndex = uniqueRootsMap[allRoots[f]];
317 uniqIndex = RegionId( k );
320 uniqueRootsMap[f] = uniqIndex;
322 return { std::move( uniqueRootsMap ), k };
#define MR_TIMER
FUNCTION in GCC/Clang returns only short function name without class name and template parameters
Definition MRTimer.h:56
stores index of some element, it is made as template class to avoid mixing faces, edges and vertices
Definition MRId.h:20
std::vector<T>-like container that requires specific indexing type,
Definition MRVector.h:23
SizeType sizeOfComp(I a)
returns the number of elements in the set containing given element
Definition MRUnionFind.h:203
std::pair< I, bool > unite(I first, I second)
Definition MRUnionFind.h:181
I updateRootInRange_(I a, const I r, I begin, I end)
sets new root
Definition MRUnionFind.h:119
ParallelUnionFind(size_t size)
creates union-find with given number of elements, each element is the only one in its disjoint set
Definition MRUnionFind.h:224
BaseUnionFind(BaseUnionFind &&) noexcept=default
I updateRoot_(I a, const I r)
sets new root
Definition MRUnionFind.h:103
auto size() const
returns the number of elements in union-find
Definition MRUnionFind.h:35
bool isRoot(I a) const
returns true if given element is the root of some set
Definition MRUnionFind.h:68
const Vector< I, I > & parents() const
gets the parents of all elements as is
Definition MRUnionFind.h:91
std::pair< I, bool > uniteUnbalanced(I first, I second)
Definition MRUnionFind.h:51
I updateRoot_(I a)
find the root of given element, and set it as parent for it and other parents
Definition MRUnionFind.h:116
const Vector< I, I > & roots()
sets the root of corresponding set as the parent of each element, then returns the vector
Definition MRUnionFind.h:83
ParallelUnionFind()=default
UnionFind(BaseUnionFind< I > &&base)
Definition MRUnionFind.h:164
UnionFind(size_t size)
creates union-find with given number of elements, each element is the only one in its disjoint set
Definition MRUnionFind.h:160
BaseUnionFind(const BaseUnionFind &)=default
void reset(size_t size)
resets union-find to represent given number of elements, each element is the only one in its disjoint...
Definition MRUnionFind.h:172
class MRMESH_CLASS I
Definition MRMeshFwd.h:141
bool united(I first, I second)
returns true if given two elements are from one set
Definition MRUnionFind.h:62
TypedBitSet< Id< T > > TaggedBitSet
Definition MRMeshFwd.h:174
I find(I a)
finds the root of the set containing given element with optimizing data structure updates
Definition MRUnionFind.h:74
typename I::ValueType SizeType
the type that can hold the number of elements of the maximal set (e.g. int for FaceId and size_t for ...
Definition MRUnionFind.h:26
void uniteAtomic(I first, I second)
Definition MRUnionFind.h:228
I parent(I a) const
return parent element of this element, which is equal to given element only for set's root
Definition MRUnionFind.h:71
typename I::ValueType SizeType
the type that can hold the number of elements of the maximal set (e.g. int for FaceId and size_t for ...
Definition MRUnionFind.h:155
Vector< I, I > parents_
parent element of each element
Definition MRUnionFind.h:138
I findRootNoUpdate_(I a) const
finds the root of the set containing given element without optimizing data structure updates
Definition MRUnionFind.h:95
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:77
void reset(size_t size)
resets union-find to represent given number of elements, each element is the only one in its disjoint...
Definition MRUnionFind.h:38
auto begin(ViewportMask mask)
Definition MRViewportId.h:122
auto end(ViewportMask)
Definition MRViewportId.h:124
only for bindings generation
Definition MRCameraOrientationPlugin.h:8