3 #ifndef DUNE_BLOCK_BITFIELD_HH 4 #define DUNE_BLOCK_BITFIELD_HH 34 template <
int block_size,
class Alloc>
54 typedef std::bitset<block_size>
bitset;
57 typedef typename std::vector<bool, Alloc>::const_reference
reference;
171 for(
int i=0; i<block_size; ++i)
190 for(
int i=0; i<block_size; ++i)
217 template <
int block_size,
class Alloc>
238 typedef typename std::vector<bool, Alloc>::reference
reference;
249 for(
int i=0; i<block_size; ++i)
257 for(
int i=0; i<block_size; ++i)
265 for(
int i=0; i<block_size; ++i)
273 for(
int i=0; i<block_size; ++i)
384 using BitSetVectorConstReference::operator[];
405 template<
int block_size,
class Alloc>
411 template<
int block_size,
class Alloc>
417 template<
int block_size,
class Alloc>
423 template<
int block_size,
class Alloc>
432 template <
int block_size,
class Allocator=std::allocator<
bool> >
433 class BitSetVector :
private std::vector<bool, Allocator>
436 typedef std::vector<bool, Allocator> BlocklessBaseClass;
458 typedef typename std::vector<bool, Allocator>::size_type
size_type;
497 BlocklessBaseClass(blocklessBitField)
499 if (blocklessBitField.size()%block_size != 0)
507 BlocklessBaseClass(n*block_size)
512 BlocklessBaseClass(n*block_size,v)
518 BlocklessBaseClass::clear();
524 BlocklessBaseClass::resize(n*block_size, v);
570 return std::count(BlocklessBaseClass::begin(), BlocklessBaseClass::end(),
true);
586 for (
size_t i=0; i<v.
size(); i++)
597 for(
int j=0; j<block_size; ++j)
598 bits.set(j, getBit(i,j));
605 return BlocklessBaseClass::operator[](i*block_size+j);
611 return BlocklessBaseClass::operator[](i*block_size+j);
BitSetVector & blockBitField
Definition: bitsetvector.hh:392
size_type countmasked(int j) const
Returns the number of set bits, while each block is masked with 1<<i.
Definition: bitsetvector.hh:574
bool operator==(const bitset &bs) const
Equality of reference and std::bitset.
Definition: bitsetvector.hh:139
BitSetVectorConstReference< block_size, Alloc > type
Definition: bitsetvector.hh:414
BitSetVectorReference & operator|=(const bitset &x)
Bitwise inclusive or (for bitset)
Definition: bitsetvector.hh:295
BitSetVectorReference & operator^=(const bitset &x)
Bitwise exclusive or (for bitset).
Definition: bitsetvector.hh:311
size_t size_type
Definition: bitsetvector.hh:59
BitSetVectorReference & operator &=(const bitset &x)
Bitwise and (for bitset).
Definition: bitsetvector.hh:279
BitSetVectorReference & reset()
Clears every bit.
Definition: bitsetvector.hh:359
void unsetAll()
Sets all entries to false
Definition: bitsetvector.hh:539
reference back()
Return reference to last block.
Definition: bitsetvector.hh:556
BitSetVectorReference & operator=(const BitSetVectorReference &b)
Assignment from BitSetVectorReference.
Definition: bitsetvector.hh:271
Dune::GenericIterator< BitSetVector< block_size, Allocator >, value_type, reference, std::ptrdiff_t, ForwardIteratorFacade > iterator
Definition: bitsetvector.hh:466
bool all() const
Returns true if all bits are set.
Definition: bitsetvector.hh:113
std::bitset< block_size > bitset
Definition: bitsetvector.hh:233
size_t size_type
size_type typedef (an unsigned integral type)
Definition: bitsetvector.hh:244
const BitSetVector & blockBitField
Definition: bitsetvector.hh:178
bool eq(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test for equality using epsilon
Definition: float_cmp.cc:118
BitSetVector(const BlocklessBaseClass &blocklessBitField)
Construction from an unblocked bitfield.
Definition: bitsetvector.hh:496
BitSetVectorReference< block_size, Alloc > type
Definition: bitsetvector.hh:420
BitSetVectorConstReference< block_size, Allocator > * const_pointer
Const pointer to a small block of bits.
Definition: bitsetvector.hh:455
size_type count() const
Returns the number of bits that are set.
Definition: bitsetvector.hh:92
BitSetVector(int n, bool v)
Constructor which initializes the field with true or false.
Definition: bitsetvector.hh:511
size_type size() const
Returns block_size.
Definition: bitsetvector.hh:86
BitSetVectorReference & operator<<=(size_type n)
Left shift.
Definition: bitsetvector.hh:327
int block_number
Definition: bitsetvector.hh:179
const_reference back() const
Return const reference to last block.
Definition: bitsetvector.hh:562
Get the 'const' version of a reference to a mutable object.
Definition: genericiterator.hh:84
std::vector< bool, Alloc >::const_reference reference
Definition: bitsetvector.hh:57
BitSetVectorReference & operator=(const bitset &b)
Assignment from bitset.
Definition: bitsetvector.hh:255
const_iterator end() const
Returns a const_iterator pointing to the end of the vector.
Definition: bitsetvector.hh:486
A proxy class that acts as a const reference to a single bitset in a BitSetVector.
Definition: bitsetvector.hh:35
Dune::GenericIterator< const BitSetVector< block_size, Allocator >, const value_type, const_reference, std::ptrdiff_t, ForwardIteratorFacade > const_iterator
Definition: bitsetvector.hh:467
Generic class for stl-conforming iterators for container classes with operator[]. ...
Definition: genericiterator.hh:149
friend std::ostream & operator<<(std::ostream &s, const BitSetVector &v)
Send bitfield to an output stream.
Definition: bitsetvector.hh:584
bool test(size_type n) const
Returns true if bit n is set.
Definition: bitsetvector.hh:122
std::bitset< block_size > bitset
Definition: bitsetvector.hh:54
Dune namespace.
Definition: alignment.hh:10
const_reference operator[](int i) const
Return const reference to i-th block.
Definition: bitsetvector.hh:550
const_iterator begin() const
Returns a const_iterator pointing to the beginning of the vector.
Definition: bitsetvector.hh:476
std::vector< bool, Alloc >::const_reference const_reference
A proxy class that acts as a const reference to a single bit.
Definition: bitsetvector.hh:240
BitSetVectorReference(BitSetVector &blockBitField_, int block_number_)
Definition: bitsetvector.hh:227
void clear()
Erases all of the elements.
Definition: bitsetvector.hh:516
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:138
bitset operator~() const
Returns a copy of *this with all of its bits flipped.
Definition: bitsetvector.hh:78
reference operator[](int i)
Return reference to i-th block.
Definition: bitsetvector.hh:544
A few common exception classes.
BitSetVectorReference & flip(size_type n)
Flips bit n.
Definition: bitsetvector.hh:377
Macro for wrapping boundary checks.
BitSetVectorConstReference(const BitSetVector &blockBitField_, int block_number_)
Definition: bitsetvector.hh:42
Allocator allocator_type
The type of the allocator.
Definition: bitsetvector.hh:461
BitSetVectorReference< block_size, Allocator > reference
Reference to a small block of bits.
Definition: bitsetvector.hh:446
const_reference operator[](size_type i) const
Definition: bitsetvector.hh:127
bool any() const
Returns true if any bits are set.
Definition: bitsetvector.hh:101
bool test(size_type n) const
Returns true if bit n is set.
Definition: bitsetvector.hh:122
BitSetVectorReference & flip()
Flips the value of every bit.
Definition: bitsetvector.hh:351
bitset operator<<(size_type n) const
Returns a copy of *this shifted left by n bits.
Definition: bitsetvector.hh:62
Default exception class for range errors.
Definition: exceptions.hh:252
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
BitSetVector()
Default constructor.
Definition: bitsetvector.hh:491
BitSetVector(int n)
Definition: bitsetvector.hh:506
BitSetVectorReference & operator|=(const BitSetVectorConstReference &x)
Bitwise inclusive or (for BitSetVectorConstReference and BitSetVectorReference)
Definition: bitsetvector.hh:303
A proxy class that acts as a mutable reference to a single bitset in a BitSetVector.
Definition: bitsetvector.hh:22
BitSetVectorReference & operator=(bool b)
Assignment from bool, sets each bit in the bitset to b.
Definition: bitsetvector.hh:247
BitSetVectorConstReference< block_size, Alloc > type
Definition: bitsetvector.hh:408
std::bitset< block_size > value_type
Type of the values stored by the container.
Definition: bitsetvector.hh:443
get the 'mutable' version of a reference to a const object
Definition: genericiterator.hh:113
BitSetVectorReference & operator>>=(size_type n)
Right shift.
Definition: bitsetvector.hh:335
bool none() const
Returns true if no bits are set.
Definition: bitsetvector.hh:107
iterator end()
Returns an iterator pointing to the end of the vector.
Definition: bitsetvector.hh:481
void setAll()
Sets all entries to true
Definition: bitsetvector.hh:534
std::vector< bool, Allocator >::size_type size_type
size type
Definition: bitsetvector.hh:458
A dynamic array of blocks of booleans.
Definition: bitsetvector.hh:21
bool operator!=(const bitset &bs) const
Inequality of reference and std::bitset.
Definition: bitsetvector.hh:151
Dune::BitSetVector< block_size, Alloc > BitSetVector
Definition: bitsetvector.hh:39
size_type size() const
Return the number of blocks.
Definition: bitsetvector.hh:528
const_reference getBit(size_type i) const
Definition: bitsetvector.hh:181
std::vector< bool, Alloc >::const_reference const_reference
Definition: bitsetvector.hh:58
BitSetVectorReference & reset(size_type n)
Clears bit n.
Definition: bitsetvector.hh:370
BitSetVectorReference< block_size, Alloc > type
Definition: bitsetvector.hh:426
constexpr auto size(const Dune::FieldVector< T, i > *, const PriorityTag< 5 > &) -> decltype(std::integral_constant< std::size_t, i >())
Definition: hybridutilities.hh:22
BitSetVectorReference & operator^=(const BitSetVectorConstReference &x)
Bitwise exclusive or (for BitSetVectorConstReference and BitSetVectorReference)
Definition: bitsetvector.hh:319
Implements a generic iterator class for writing stl conformant iterators.
iterator begin()
Returns a iterator pointing to the beginning of the vector.
Definition: bitsetvector.hh:471
bool equals(const BS &bs) const
Definition: bitsetvector.hh:187
std::vector< bool, Alloc >::reference reference
Definition: bitsetvector.hh:238
reference operator[](size_type i)
Definition: bitsetvector.hh:386
Dune::BitSetVectorConstReference< block_size, Alloc > BitSetVectorConstReference
Definition: bitsetvector.hh:225
BitSetVectorConstReference & operator=(const BitSetVectorConstReference &b)
hide assignment operator
BitSetVectorReference & operator=(const BitSetVectorConstReference &b)
Assignment from BitSetVectorConstReference.
Definition: bitsetvector.hh:263
reference getBit(size_type i)
Definition: bitsetvector.hh:396
size_type count() const
Returns the number of bits that are set.
Definition: bitsetvector.hh:568
bitset operator>>(size_type n) const
Returns a copy of *this shifted right by n bits.
Definition: bitsetvector.hh:70
void resize(int n, bool v=bool())
Resize field.
Definition: bitsetvector.hh:522
BitSetVectorConstReference< block_size, Allocator > const_reference
Const reference to a small block of bits.
Definition: bitsetvector.hh:449
Dune::BitSetVector< block_size, Alloc > BitSetVector
Definition: bitsetvector.hh:222
BitSetVectorReference< block_size, Allocator > * pointer
Pointer to a small block of bits.
Definition: bitsetvector.hh:452
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition: boundschecking.hh:28