20 #ifndef GEOS_LINEARALGEBRA_UTILITIES_COMPONENTMASK_HPP_
21 #define GEOS_LINEARALGEBRA_UTILITIES_COMPONENTMASK_HPP_
35 template<
typename T >
36 constexpr
bool always_false( T )
42 struct ComponentMaskType
44 static_assert( always_false( N ),
"Unsupported template parameter N for ComponentMask. Use a value between 8 and 64." );
50 #define GEOS_LAI_COMPONENTMASK_DECL( N ) \
52 struct ComponentMaskType< N > \
54 using type = std::uint ## N ## _t; \
62 #undef GEOS_LAI_COMPONENTMASK_DECL
64 constexpr std::uint32_t roundToNextPowerOfTwo( std::uint32_t v )
66 if( v <= 8 )
return 8;
89 template<
int MAX_COMP >
95 static constexpr
int NUM_BITS = internal::roundToNextPowerOfTwo( MAX_COMP );
98 using mask_t =
typename internal::ComponentMaskType< NUM_BITS >::type;
114 : m_mask( includeAll ? -1 : 0 )
139 for(
int i = lo; i < hi; ++i )
150 template<
int N,
typename = std::enable_if_t< ( N < MAX_COMP ) > >
152 ComponentMask( ComponentMask< N > const & other )
153 : m_numComp( other.numComp() )
176 using difference_type =
int;
177 using value_type =
int;
178 using po
inter =
void;
179 using reference =
int;
180 using iterator_category = std::forward_iterator_tag;
188 reference operator*() const
199 Iterator & operator++()
201 GEOS_ASSERT_NE( m_mask, 0 );
213 Iterator operator++(
int ) &
215 Iterator old = *this;
227 bool operator==( Iterator const & other ) const
229 return m_mask == other.m_mask;
239 bool operator!=( Iterator const & other ) const
241 return !(*this == other);
261 while( !( m_mask & 1 ) )
269 Iterator( mask_t
const mask,
int const index )
276 friend class ComponentMask;
306 mask_t mask = m_mask;
308 for(; mask != 0; ++c )
342 return m_mask & (mask_t( 1 ) << i);
371 if( numComp < NUM_BITS )
373 m_mask &= ( mask_t( 1 ) << numComp ) - 1;
386 m_mask |= mask_t( 1 ) << i;
398 m_mask &= ~(mask_t( 1 ) << i);
408 setNumComp( m_numComp );
507 int m_numComp = MAX_COMP;
#define GEOS_LAI_COMPONENTMASK_DECL(N)
Macro for declaring a specialization of ComponentMaskTypeImpl template.
#define GEOS_HOST_DEVICE
Marks a host-device function.
#define GEOS_FORCE_INLINE
Marks a function or lambda for inlining.
#define GEOS_ASSERT_GT(lhs, rhs)
Assert that one value compares greater than the other in debug builds.
#define GEOS_ASSERT_GE(lhs, rhs)
Assert that one value compares greater than or equal to the other in debug builds.
Forward const iterator over the set components (bits).
Utility class that represents a mask for included/excluded component of a mask.
GEOS_HOST_DEVICE bool empty() const
GEOS_HOST_DEVICE void invert()
Invert component selection.
GEOS_HOST_DEVICE int numComp() const
GEOS_HOST_DEVICE void clear()
Clear the mask, removing selected components.
GEOS_HOST_DEVICE void unset(int const i)
Remove a component.
GEOS_HOST_DEVICE bool operator[](int const i) const
Check if a particular component is selected.
GEOS_HOST_DEVICE ComponentMask & operator-=(int const i)
Remove a component.
GEOS_HOST_DEVICE ComponentMask operator~() const
Negation operator (inverts component selection).
GEOS_HOST_DEVICE ComponentMask(int const numComp, int const lo, int const hi)
Range constructor, includes contiguous range of components.
GEOS_HOST_DEVICE Iterator end() const
GEOS_HOST_DEVICE ComponentMask(int const numComp, bool const includeAll)
Constructor.
GEOS_HOST_DEVICE int size() const
GEOS_HOST_DEVICE void setNumComp(int const numComp)
Set new component limit and truncate all components above.
GEOS_HOST_DEVICE void set(int const i)
Add a component.
GEOS_HOST_DEVICE Iterator begin() const
GEOS_HOST_DEVICE ComponentMask & operator+=(int const i)
Add a component.
GEOS_HOST_DEVICE ComponentMask(int const numComp=0)
Constructor.
GEOS_HOST_DEVICE friend ComponentMask operator+(int const i, ComponentMask const &mask)
Make a new mask by adding a component.
GEOS_HOST_DEVICE friend ComponentMask operator-(ComponentMask const &mask, int const i)
Make a new mask by removing a component.
GEOS_HOST_DEVICE friend ComponentMask operator+(ComponentMask const &mask, int const i)
Make a new mask by adding a component.
GEOS_HOST_DEVICE friend ComponentMask operator-(int const i, ComponentMask const &mask)
Make a new mask by removing a component.
std::set< T > set
A set of local indices.