a class for storing bitwise information More...
#include "misc/bitset.h"
Classes | |
class | ConstValue |
class | Value |
Public Member Functions | |
BitSet (const size_t, const bool allocator=false) | |
create a new bitset with the desired size. More... | |
BitSet (const BitSet &) | |
copy-construct a bitset, with explicit copying of data into the new instance More... | |
~BitSet () | |
void | resize (const size_t, const bool allocator=false) |
resize the bitset, retaining existing data More... | |
void | clear (const bool allocator=false) |
clear the data More... | |
ConstValue | operator[] (const size_t i) const |
access boolean value at a given index More... | |
Value | operator[] (const size_t i) |
size_t | size () const |
the number of boolean elements in the set More... | |
bool | full () const |
whether or not the bitset is 'full' i.e. all elements are true More... | |
bool | empty () const |
whether or not the bitset is 'empty' i.e. all elements are false More... | |
size_t | count () const |
count the number of true entries in the set More... | |
BitSet & | operator= (const BitSet &) |
convenience functions for performing boolean operations More... | |
bool | operator== (const BitSet &) const |
bool | operator!= (const BitSet &) const |
BitSet & | operator|= (const BitSet &) |
BitSet & | operator&= (const BitSet &) |
BitSet & | operator^= (const BitSet &) |
BitSet | operator| (const BitSet &) const |
BitSet | operator& (const BitSet &) const |
BitSet | operator^ (const BitSet &) const |
BitSet | operator~ () const |
const uint8_t * | get_data_ptr () const |
Protected Member Functions | |
bool | have_excess_bits () const |
size_t | excess_bits () const |
uint8_t | excess_bit_mask () const |
bool | test (const size_t index) const |
void | set (const size_t index) |
void | reset (const size_t index) |
Protected Attributes | |
size_t | bits |
size_t | bytes |
Friends | |
std::ostream & | operator<< (std::ostream &, const BitSet &) |
a class for storing bitwise information
The BitSet class stores information in a bitwise fashion. Only a single bit of memory is used for each bit of information. Unlike the std::bitset class, the size of the BitSet can be specified (and modified) at runtime.
This class is useful for storing a single boolean value (true or false) for each element of some vector. It may also be useful for two-dimensional data, though the programmer is responsible for performing the conversion from a two-dimensional position to an array index. If a boolean value for each voxel is required for three- or four-dimensional data, use of an Image::BufferScratch<bool> is recommended.
MR::BitSet::BitSet | ( | const | size_t, |
const bool | allocator = false |
||
) |
create a new bitset with the desired size.
If allocator is unspecified or set to false, the initial value for each element will be false. If it is specified as true, then all data will be initialised as true.
MR::BitSet::BitSet | ( | const BitSet & | ) |
copy-construct a bitset, with explicit copying of data into the new instance
The BitSet copy-constructor explicitly copies all of the data from the constructing instance into the new instance. Therefore, their sizes and data will be identical, but subsequent modifications to the data in one instance will not affect the other.
MR::BitSet::~BitSet | ( | ) |
void MR::BitSet::clear | ( | const bool | allocator = false | ) |
clear the data
Clears all existing data in the BitSet. By default all values will be set to false; if allocator is explicitly set to true, then all values will be set to true.
size_t MR::BitSet::count | ( | ) | const |
count the number of true entries in the set
Convenience function for counting the number of true entries in the set. This can be useful if the programmer chooses not to manually keep track of the number of entries set or not set. The number of entries in the data that are set to false can be calculated as:
bool MR::BitSet::empty | ( | ) | const |
whether or not the bitset is 'empty' i.e. all elements are false
Convenience function for testing whether or not the BitSet is 'empty', i.e. all elements in the array are set to false. This can be useful if the programmer chooses not to manually keep track of the number of entries set or not set. Because it processes the data in bytes rather than bits, it is faster than the programmer manually performing this calculation.
|
inlineprotected |
bool MR::BitSet::full | ( | ) | const |
whether or not the bitset is 'full' i.e. all elements are true
Convenience function for testing whether or not the BitSet is 'full', i.e. all elements in the array are set to true. This can be useful if the programmer chooses not to manually keep track of the number of entries set or not set. Because it processes the data in bytes rather than bits, it is faster than the programmer manually performing this calculation.
|
inlineprotected |
bool MR::BitSet::operator!= | ( | const BitSet & | ) | const |
convenience functions for performing boolean operations
Convenience function for performing boolean operations using BitSet data. Each of these functions performs a particular boolean operation, but for all of the data in the array. Because they process the data in bytes rather than bits, they are faster than if the programmer manually performed these operations on a per-bit basis.
Particular notes of interest:
bool MR::BitSet::operator== | ( | const BitSet & | ) | const |
|
inline |
access boolean value at a given index
These functions provide access to the raw boolean data using the [] (square-bracket) operator. Both const and non-const versions are provided. Although internally the BitSet class stores eight boolean values in each byte of memory (to minimise memory usage), these operators can be used to access and manipulate the bit wise data without corrupting the surrounding data.
BitSet MR::BitSet::operator~ | ( | ) | const |
|
inlineprotected |
void MR::BitSet::resize | ( | const | size_t, |
const bool | allocator = false |
||
) |
resize the bitset, retaining existing data
Modify the size of the BitSet. Existing data information will be retained by the resizing process. If the new size is smaller than the existing size, then all excess data will be truncated. If the new size is larger than the existing size, then all existing data will be retained, and additional bits beyond the previous size will be set to false; unless allocator is explicitly provided as true, in which case all additional bits will be set to true.
|
inline |
|
inlineprotected |
|
friend |