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{
11
12
15template <typename I>
16TypedBitSet<I> findRootsBitSet( const UnionFind<I> & uf, const TypedBitSet<I> * region = nullptr )
17{
19 TypedBitSet<I> res( uf.size() );
20 BitSetParallelForAll( res, [&]( I i )
21 {
22 if ( region && !region->test( i ) )
23 return;
24 if ( uf.isRoot( i ) )
25 res.set( i );
26 } );
27 return res;
28}
29
32template <typename I>
33TypedBitSet<I> findComponentBitSet( UnionFind<I> & uf, I a, const TypedBitSet<I> * region = nullptr )
34{
36 TypedBitSet<I> res( uf.size() );
37 a = uf.find( a );
38 BitSetParallelForAllRanged( res, [&]( I i, const auto & range )
39 {
40 if ( region && !region->test( i ) )
41 return;
42 if ( a == uf.findUpdateRange( i, range.beg, range.end ) )
43 res.set( i );
44 } );
45 return res;
46}
47
48}
#define MR_TIMER
namespace MR
Definition MRTimer.h:56
Definition MRBitSet.h:229
TypedBitSet & set(IndexType n, size_type len, bool val)
Definition MRBitSet.h:241
Union-find data structure for representing disjoin sets of elements with few very quick operations: 1...
Definition MRUnionFind.h:23
auto BitSetParallelForAll(const BS &bs, F &&f, Cb &&... cb)
Definition MRBitSetParallelFor.h:133
auto BitSetParallelForAllRanged(const BS &bs, F &&... f)
namespace BitSetParallel
Definition MRBitSetParallelFor.h:111
I find(I a)
finds the root of the set containing given element with optimizing data structure updates
Definition MRUnionFind.h:86
bool isRoot(I a) const
returns true if given element is the root of some set
Definition MRUnionFind.h:80
auto size() const
returns the number of elements in union-find
Definition MRUnionFind.h:34
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:89
TypedBitSet< I > findComponentBitSet(UnionFind< I > &uf, I a, const TypedBitSet< I > *region=nullptr)
Definition MRUnionFindParallel.h:33
TypedBitSet< I > findRootsBitSet(const UnionFind< I > &uf, const TypedBitSet< I > *region=nullptr)
Definition MRUnionFindParallel.h:16
only for bindings generation
Definition MRCameraOrientationPlugin.h:8