19 #ifndef GEOS_LINEARALGEBRA_UTILITIES_COMPONENTMASK_HPP_
20 #define GEOS_LINEARALGEBRA_UTILITIES_COMPONENTMASK_HPP_
34 template<
typename T >
35 constexpr
bool always_false( T )
41 struct ComponentMaskType
43 static_assert( always_false( N ),
"Unsupported template parameter N for ComponentMask. Use a value between 8 and 64." );
49 #define GEOS_LAI_COMPONENTMASK_DECL( N ) \
51 struct ComponentMaskType< N > \
53 using type = std::uint ## N ## _t; \
61 #undef GEOS_LAI_COMPONENTMASK_DECL
63 constexpr std::uint32_t roundToNextPowerOfTwo( std::uint32_t v )
65 if( v <= 8 )
return 8;
88 template<
int MAX_COMP >
94 static constexpr
int NUM_BITS = internal::roundToNextPowerOfTwo( MAX_COMP );
97 using mask_t =
typename internal::ComponentMaskType< NUM_BITS >::type;
113 : m_mask( includeAll ? -1 : 0 )
138 for(
int i = lo; i < hi; ++i )
149 template<
int N,
typename = std::enable_if_t< ( N < MAX_COMP ) > >
151 ComponentMask( ComponentMask< N > const & other )
152 : m_numComp( other.numComp() )
175 using difference_type =
int;
176 using value_type =
int;
177 using po
inter =
void;
178 using reference =
int;
179 using iterator_category = std::forward_iterator_tag;
187 reference operator*() const
198 Iterator & operator++()
200 GEOS_ASSERT_NE( m_mask, 0 );
212 Iterator operator++(
int ) &
214 Iterator old = *this;
226 bool operator==( Iterator const & other ) const
228 return m_mask == other.m_mask;
238 bool operator!=( Iterator const & other ) const
240 return !(*this == other);
260 while( !( m_mask & 1 ) )
268 Iterator( mask_t
const mask,
int const index )
275 friend class ComponentMask;
305 mask_t mask = m_mask;
307 for(; mask != 0; ++c )
341 return m_mask & (mask_t( 1 ) << i);
370 if( numComp < NUM_BITS )
372 m_mask &= ( mask_t( 1 ) << numComp ) - 1;
385 m_mask |= mask_t( 1 ) << i;
397 m_mask &= ~(mask_t( 1 ) << i);
407 setNumComp( m_numComp );
506 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.