MeshLib C++ Docs
Loading...
Searching...
No Matches
MRUnionFindParallel.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRUnionFind.h"
5#include "MRTimer.h"
6
7namespace MR
8{
9
12template <typename I>
13TypedBitSet<I> findRootsBitSet( const UnionFind<I> & uf, const TypedBitSet<I> * region = nullptr )
14{
16 TypedBitSet<I> res( uf.size() );
17 BitSetParallelForAll( res, [&]( I i )
18 {
19 if ( region && !region->test( i ) )
20 return;
21 if ( uf.isRoot( i ) )
22 res.set( i );
23 } );
24 return res;
25}
26
29template <typename I>
30TypedBitSet<I> findComponentBitSet( UnionFind<I> & uf, I a, const TypedBitSet<I> * region = nullptr )
31{
33 TypedBitSet<I> res( uf.size() );
34 a = uf.find( a );
35 BitSetParallelForAllRanged( res, [&]( I i, const auto & range )
36 {
37 if ( region && !region->test( i ) )
38 return;
39 if ( a == uf.findUpdateRange( i, range.beg, range.end ) )
40 res.set( i );
41 } );
42 return res;
43}
44
45} //namespace MR
#define MR_TIMER
Definition MRTimer.h:53
container of bits representing specific indices (faces, verts or edges)
Definition MRMesh/MRBitSet.h:132
TypedBitSet & set(IndexType n, size_type len, bool val)
Definition MRMesh/MRBitSet.h:144
Union-find data structure for representing disjoin sets of elements with few very quick operations: 1...
Definition MRUnionFind.h:20
I find(I a)
finds the root of the set containing given element with optimizing data structure updates
Definition MRUnionFind.h:83
bool isRoot(I a) const
returns true if given element is the root of some set
Definition MRUnionFind.h:77
auto size() const
returns the number of elements in union-find
Definition MRUnionFind.h:31
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:86
auto BitSetParallelForAll(const BS &bs, F &&f, Cb &&... cb)
Definition MRBitSetParallelFor.h:170
auto BitSetParallelForAllRanged(const BS &bs, F &&... f)
Definition MRBitSetParallelFor.h:148
Definition MRCameraOrientationPlugin.h:8
TypedBitSet< I > findComponentBitSet(UnionFind< I > &uf, I a, const TypedBitSet< I > *region=nullptr)
Definition MRUnionFindParallel.h:30
TypedBitSet< I > findRootsBitSet(const UnionFind< I > &uf, const TypedBitSet< I > *region=nullptr)
Definition MRUnionFindParallel.h:13