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 BaseUnionFind<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( BaseUnionFind<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 BaseUnionFind<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
66template <typename I>
68{
72 tbb::parallel_for( tbb::blocked_range<I>( I( 0 ), I( uf.size() ) ),
73 [&] ( const tbb::blocked_range<I> & range )
74 {
75 for ( I i = range.begin(); i < range.end(); ++i )
76 uf.findUpdateRange( i, range.begin(), range.end() );
77 } );
78 return uf.parents();
79}
80}
#define MR_TIMER
FUNCTION in GCC/Clang returns only short function name without class name and template parameters
Definition MRTimer.h:56
base of union-find data structures: stores only the parent forest and the operations that depend on i...
Definition MRUnionFind.h:22
Definition MRBitSet.h:277
TypedBitSet & set(IndexType n, size_type len, bool val)
Definition MRBitSet.h:289
std::vector<T>-like container that requires specific indexing type,
Definition MRVector.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
bool isSubdivision(const BaseUnionFind< I > &uf, const TypedBitSet< I > &region)
Definition MRUnionFindParallel.h:52
TypedBitSet< I > findRootsBitSet(const BaseUnionFind< I > &uf, const TypedBitSet< I > *region=nullptr)
Definition MRUnionFindParallel.h:17
auto size() const
returns the number of elements in union-find
Definition MRUnionFind.h:34
bool isRoot(I a) const
returns true if given element is the root of some set
Definition MRUnionFind.h:67
const Vector< I, I > & parents() const
gets the parents of all elements as is
Definition MRUnionFind.h:90
TypedBitSet< I > findComponentBitSet(BaseUnionFind< I > &uf, I a, const TypedBitSet< I > *region=nullptr)
Definition MRUnionFindParallel.h:34
class MRMESH_CLASS I
Definition MRMeshFwd.h:141
I find(I a)
finds the root of the set containing given element with optimizing data structure updates
Definition MRUnionFind.h:73
const Vector< I, I > & updateRootsParallel(BaseUnionFind< I > &uf)
Definition MRUnionFindParallel.h:67
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:76
only for bindings generation
Definition MRCameraOrientationPlugin.h:8