5#ifndef DUNE_BLOCK_BITFIELD_HH
6#define DUNE_BLOCK_BITFIELD_HH
23 template <
int block_size,
class Alloc>
class BitSetVector;
36 template <
int block_size,
class Alloc>
56 typedef std::bitset<block_size>
bitset;
59 typedef typename std::vector<bool, Alloc>::const_reference
reference;
174 for(
int i=0; i<block_size; ++i)
193 for(
int i=0; i<block_size; ++i)
194 eq &= (
getBit(i) == bs[i]);
203 void operator & () =
delete;
220 template <
int block_size,
class Alloc>
241 typedef typename std::vector<bool, Alloc>::reference
reference;
252 for(
int i=0; i<block_size; ++i)
260 for(
int i=0; i<block_size; ++i)
268 for(
int i=0; i<block_size; ++i)
276 for(
int i=0; i<block_size; ++i)
284 return (*
this) =
bitset(*
this) & x;
290 return (*
this) &=
bitset(x);
296 return (*
this) =
bitset(*
this) | x;
302 return (*
this) |=
bitset(x);
308 return (*
this) =
bitset(*
this) ^ x;
314 return (*
this) ^=
bitset(x);
320 return (*
this) =
bitset(*
this) << n;
326 return (*
this) =
bitset(*
this) >> n;
374 using BitSetVectorConstReference::operator[];
396 template<
int block_size,
class Alloc>
402 template<
int block_size,
class Alloc>
408 template<
int block_size,
class Alloc>
414 template<
int block_size,
class Alloc>
423 template <
int block_size,
class Allocator=std::allocator<
bool> >
427 typedef std::vector<bool, Allocator> BlocklessBaseClass;
449 typedef typename std::vector<bool, Allocator>::size_type
size_type;
488 BlocklessBaseClass(blocklessBitField)
490 if (blocklessBitField.size()%block_size != 0)
498 BlocklessBaseClass(n*block_size)
503 BlocklessBaseClass(n*block_size,v)
509 BlocklessBaseClass::clear();
515 BlocklessBaseClass::resize(n*block_size, v);
521 return BlocklessBaseClass::size()/block_size;
526 this->
assign(BlocklessBaseClass::size(),
true);
531 this->
assign(BlocklessBaseClass::size(),
false);
561 return std::count(BlocklessBaseClass::begin(), BlocklessBaseClass::end(),
true);
577 for (
size_t i=0; i<v.
size(); i++)
588 for(
int j=0; j<block_size; ++j)
589 bits.set(j, getBit(i,j));
596 return BlocklessBaseClass::operator[](i*block_size+j);
602 return BlocklessBaseClass::operator[](i*block_size+j);
Implements a generic iterator class for writing stl conformant iterators.
A few common exception classes.
Macro for wrapping boundary checks.
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition boundschecking.hh:30
#define DUNE_THROW(E,...)
Definition exceptions.hh:314
Dune namespace
Definition alignedallocator.hh:13
void assign(T &dst, const T &src, bool mask)
masked Simd assignment (scalar version)
Definition simd.hh:447
A dynamic array of blocks of booleans.
Definition bitsetvector.hh:425
const_reference operator[](int i) const
Return const reference to i-th block.
Definition bitsetvector.hh:541
iterator begin()
Returns a iterator pointing to the beginning of the vector.
Definition bitsetvector.hh:462
BitSetVectorConstReference< block_size, Alloc > * const_pointer
Definition bitsetvector.hh:446
const_iterator end() const
Returns a const_iterator pointing to the end of the vector.
Definition bitsetvector.hh:477
BitSetVectorReference< block_size, Alloc > reference
Definition bitsetvector.hh:437
size_type countmasked(int j) const
Returns the number of set bits, while each block is masked with 1<<i.
Definition bitsetvector.hh:565
BitSetVectorConstReference< block_size, Alloc > const_reference
Definition bitsetvector.hh:440
iterator end()
Returns an iterator pointing to the end of the vector.
Definition bitsetvector.hh:472
size_type count() const
Returns the number of bits that are set.
Definition bitsetvector.hh:559
BitSetVector()
Default constructor.
Definition bitsetvector.hh:482
void setAll()
Sets all entries to true .
Definition bitsetvector.hh:525
Dune::GenericIterator< const BitSetVector< block_size, Alloc >, const value_type, const_reference, std::ptrdiff_t, ForwardIteratorFacade > const_iterator
Definition bitsetvector.hh:458
std::bitset< block_size > value_type
Definition bitsetvector.hh:434
reference back()
Return reference to last block.
Definition bitsetvector.hh:547
BitSetVector(const BlocklessBaseClass &blocklessBitField)
Construction from an unblocked bitfield.
Definition bitsetvector.hh:487
friend std::ostream & operator<<(std::ostream &s, const BitSetVector &v)
Send bitfield to an output stream.
Definition bitsetvector.hh:575
const_reference back() const
Return const reference to last block.
Definition bitsetvector.hh:553
void clear()
Erases all of the elements.
Definition bitsetvector.hh:507
BitSetVectorReference< block_size, Alloc > * pointer
Definition bitsetvector.hh:443
reference operator[](int i)
Return reference to i-th block.
Definition bitsetvector.hh:535
size_type size() const
Return the number of blocks.
Definition bitsetvector.hh:519
std::vector< bool, Alloc >::size_type size_type
Definition bitsetvector.hh:449
BitSetVector(int n, bool v)
Constructor which initializes the field with true or false.
Definition bitsetvector.hh:502
const_iterator begin() const
Returns a const_iterator pointing to the beginning of the vector.
Definition bitsetvector.hh:467
Dune::GenericIterator< BitSetVector< block_size, Alloc >, value_type, reference, std::ptrdiff_t, ForwardIteratorFacade > iterator
Definition bitsetvector.hh:457
void resize(int n, bool v=bool())
Resize field.
Definition bitsetvector.hh:513
Alloc allocator_type
Definition bitsetvector.hh:452
BitSetVector(int n)
Definition bitsetvector.hh:497
void unsetAll()
Sets all entries to false .
Definition bitsetvector.hh:530
A proxy class that acts as a mutable reference to a single bitset in a BitSetVector.
Definition bitsetvector.hh:222
bool test(size_type n) const
Returns true if bit n is set.
Definition bitsetvector.hh:124
BitSetVectorReference & operator=(const BitSetVectorConstReference &b)
Assignment from BitSetVectorConstReference.
Definition bitsetvector.hh:266
reference operator[](size_type i)
Return reference to the i-th bit.
Definition bitsetvector.hh:377
BitSetVectorReference & reset(size_type n)
Clears bit n.
Definition bitsetvector.hh:360
BitSetVectorReference & operator<<=(size_type n)
Left shift.
Definition bitsetvector.hh:318
Dune::BitSetVector< block_size, Alloc > BitSetVector
Definition bitsetvector.hh:225
std::vector< bool, Alloc >::const_reference const_reference
A proxy class that acts as a const reference to a single bit.
Definition bitsetvector.hh:243
BitSetVectorReference & operator=(const BitSetVectorReference &b)
Assignment from BitSetVectorReference.
Definition bitsetvector.hh:274
reference getBit(size_type i)
Definition bitsetvector.hh:387
BitSetVectorReference & operator&=(const BitSetVectorConstReference &x)
Bitwise and (for BitSetVectorConstReference and BitSetVectorReference).
Definition bitsetvector.hh:288
BitSetVectorReference(BitSetVector &blockBitField_, int block_number_)
Definition bitsetvector.hh:230
size_t size_type
size_type typedef (an unsigned integral type)
Definition bitsetvector.hh:247
BitSetVectorReference & operator=(const bitset &b)
Assignment from bitset.
Definition bitsetvector.hh:258
Dune::BitSetVectorConstReference< block_size, Alloc > BitSetVectorConstReference
Definition bitsetvector.hh:228
BitSetVectorReference & reset()
Clears every bit.
Definition bitsetvector.hh:346
BitSetVector & blockBitField
Definition bitsetvector.hh:383
BitSetVectorReference & operator|=(const BitSetVectorConstReference &x)
Bitwise inclusive or (for BitSetVectorConstReference and BitSetVectorReference).
Definition bitsetvector.hh:300
BitSetVectorReference & set(size_type n, int val=1)
Sets bit n if val is nonzero, and clears bit n if val is zero.
Definition bitsetvector.hh:353
std::bitset< block_size > bitset
Definition bitsetvector.hh:236
BitSetVectorReference & operator^=(const bitset &x)
Bitwise exclusive or (for bitset).
Definition bitsetvector.hh:306
std::vector< bool, Alloc >::reference reference
Definition bitsetvector.hh:241
BitSetVectorReference & operator|=(const bitset &x)
Bitwise inclusive or (for bitset).
Definition bitsetvector.hh:294
BitSetVectorReference & operator>>=(size_type n)
Right shift.
Definition bitsetvector.hh:324
BitSetVectorReference & operator^=(const BitSetVectorConstReference &x)
Bitwise exclusive or (for BitSetVectorConstReference and BitSetVectorReference).
Definition bitsetvector.hh:312
BitSetVectorReference & flip(size_type n)
Flips bit n.
Definition bitsetvector.hh:367
BitSetVectorReference & flip()
Flips the value of every bit.
Definition bitsetvector.hh:338
BitSetVectorReference & set()
Sets every bit.
Definition bitsetvector.hh:330
BitSetVectorReference & operator&=(const bitset &x)
Bitwise and (for bitset).
Definition bitsetvector.hh:282
BitSetVectorReference & operator=(bool b)
Assignment from bool, sets each bit in the bitset to b.
Definition bitsetvector.hh:250
A proxy class that acts as a const reference to a single bitset in a BitSetVector.
Definition bitsetvector.hh:38
bool operator==(const bitset &bs) const
Equality of reference and std::bitset.
Definition bitsetvector.hh:142
bool test(size_type n) const
Returns true if bit n is set.
Definition bitsetvector.hh:124
const_reference operator[](size_type i) const
Return reference to the i-th bit.
Definition bitsetvector.hh:130
bitset operator<<(size_type n) const
Returns a copy of *this shifted left by n bits.
Definition bitsetvector.hh:64
BitSetVectorConstReference(const BitSetVector &blockBitField_, int block_number_)
Definition bitsetvector.hh:44
const BitSetVector & blockBitField
Definition bitsetvector.hh:181
bitset operator>>(size_type n) const
Returns a copy of *this shifted right by n bits.
Definition bitsetvector.hh:72
const_reference getBit(size_type i) const
Definition bitsetvector.hh:184
bool operator!=(const bitset &bs) const
Inequality of reference and std::bitset.
Definition bitsetvector.hh:154
bool equals(const BS &bs) const
Definition bitsetvector.hh:190
Dune::BitSetVector< block_size, Alloc > BitSetVector
Definition bitsetvector.hh:41
std::bitset< block_size > bitset
Definition bitsetvector.hh:56
bool all() const
Returns true if all bits are set.
Definition bitsetvector.hh:115
size_t size_type
Definition bitsetvector.hh:61
bitset operator~() const
Returns a copy of *this with all of its bits flipped.
Definition bitsetvector.hh:80
std::vector< bool, Alloc >::const_reference reference
Definition bitsetvector.hh:59
size_type size() const
Returns block_size.
Definition bitsetvector.hh:88
size_type count() const
Returns the number of bits that are set.
Definition bitsetvector.hh:94
bool none() const
Returns true if no bits are set.
Definition bitsetvector.hh:109
bool any() const
Returns true if any bits are set.
Definition bitsetvector.hh:103
int block_number
Definition bitsetvector.hh:182
std::vector< bool, Alloc >::const_reference const_reference
Definition bitsetvector.hh:60
BitSetVectorConstReference & operator=(const BitSetVectorConstReference &b)=delete
disable assignment operator
BitSetVectorConstReference< block_size, Alloc > type
Definition bitsetvector.hh:399
BitSetVectorConstReference< block_size, Alloc > type
Definition bitsetvector.hh:405
BitSetVectorReference< block_size, Alloc > type
Definition bitsetvector.hh:411
BitSetVectorReference< block_size, Alloc > type
Definition bitsetvector.hh:417
Default exception class for range errors.
Definition exceptions.hh:348
Get the 'const' version of a reference to a mutable object.
Definition genericiterator.hh:87
get the 'mutable' version of a reference to a const object
Definition genericiterator.hh:116
Generic class for stl-conforming iterators for container classes with operator[].
Definition genericiterator.hh:153
Base class for stl conformant forward iterators.
Definition iteratorfacades.hh:142