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 "MRParallelFor.h"
6#include "MRTimer.h"
7
8namespace MR
9{
12
13
16template <typename I>
17[[nodiscard]] TypedBitSet<I> findRootsBitSet( const UnionFind<I> & uf, const TypedBitSet<I> * region = nullptr )
18{
20 TypedBitSet<I> res( uf.size() );
21 BitSetParallelForAll( res, [&]( I i )
22 {
23 if ( region && !region->test( i ) )
24 return;
25 if ( uf.isRoot( i ) )
26 res.set( i );
27 } );
28 return res;
29}
30
33template <typename I>
34[[nodiscard]] TypedBitSet<I> findComponentBitSet( UnionFind<I> & uf, I a, const TypedBitSet<I> * region = nullptr )
35{
37 TypedBitSet<I> res( uf.size() );
38 a = uf.find( a );
39 BitSetParallelForAllRanged( res, [&]( I i, const auto & range )
40 {
41 if ( region && !region->test( i ) )
42 return;
43 if ( a == uf.findUpdateRange( i, range.beg, range.end ) )
44 res.set( i );
45 } );
46 return res;
47}
48
51template <typename I>
52[[nodiscard]] bool isSubdivision( const UnionFind<I> & uf, const TypedBitSet<I> & region )
53{
55 tbb::task_group_context ctx;
56 ParallelFor( I( 0 ), I( uf.size() ), [&]( I i )
57 {
58 if ( region.test( uf.parent( i ) ) != region.test( i ) )
59 ctx.cancel_group_execution();
60 }, ctx );
61 return !ctx.is_group_execution_cancelled();
62}
63}
#define MR_TIMER
FUNCTION in GCC/Clang returns only short function name without class name and template parameters
Definition MRTimer.h:56
Definition MRBitSet.h:277
TypedBitSet & set(IndexType n, size_type len, bool val)
Definition MRBitSet.h:289
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)
Definition MRBitSetParallelFor.h:111
auto ParallelFor(I begin, I end, F &&f, Cb &&... cb)
Definition MRParallelFor.h:30
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
class MRMESH_CLASS I
Definition MRMeshFwd.h:139
bool isSubdivision(const UnionFind< I > &uf, const TypedBitSet< I > &region)
Definition MRUnionFindParallel.h:52
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:34
TypedBitSet< I > findRootsBitSet(const UnionFind< I > &uf, const TypedBitSet< I > *region=nullptr)
Definition MRUnionFindParallel.h:17
only for bindings generation
Definition MRCameraOrientationPlugin.h:8