This class uses bit representation to store many small sets. More...
#include <chomp/struct/bitsets.h>
Public Member Functions | |
BitSets (int_t _nsets, int_t _nelem) | |
Constructor of a family of empty sets. | |
BitSets (const BitSets &s) | |
Copy constructor. | |
BitSets & | operator= (const BitSets &s) |
Assignment operator. | |
~BitSets () | |
Destructor. | |
void | add (int_t n, int_t e) |
Adds an element to the given set. | |
void | remove (int_t n, int_t e) |
Removes an element from the given set. | |
bool | check (int_t n, int_t e) const |
Checks if an element belongs to the given set. | |
void | addset (int_t n, int_t m) |
Adds the entire set 'm' to the set 'n'. | |
int_t | get (int_t n, int_t start=0) const |
Retrieves an element >= 'start' in the given set. | |
Private Member Functions | |
int_t | arraySize () |
Computes the size of the memory array for storing the bits. | |
Private Attributes | |
int_t | nsets |
The number of sets. | |
int_t | nelem |
The maximal number of elements in each set. | |
int_t | nunits |
The number of array entries used for each set. | |
unsigned long * | bits |
The memory buffer for storing the bits. | |
Static Private Attributes | |
static const int_t | longBits = sizeof (long) * 8 |
static const int_t | longBitMask = longBits - 1 |
static const int_t | longBitShift = (sizeof (long) == 8) ? 6 : 5 |
This class uses bit representation to store many small sets.
Each of the sets can contain integer numbers from 0 to the limit specified in the constructor. The number of sets must also be given in the constructor. A contiguous chunk of memory is used to store the bits that represent the sets. This class is not fool-proof, so use it carefully. Minimal interface, sorry.
Definition at line 58 of file bitsets.h.
chomp::homology::BitSets::BitSets | ( | int_t | _nsets, |
int_t | _nelem | ||
) | [inline] |
Constructor of a family of empty sets.
The number of the sets and the maximal number of elements in each set must be provided at initialization. Both numbers must be positive.
Definition at line 124 of file bitsets.h.
References arraySize(), and bits.
chomp::homology::BitSets::BitSets | ( | const BitSets & | s ) | [inline] |
chomp::homology::BitSets::~BitSets | ( | ) | [inline] |
void chomp::homology::BitSets::add | ( | int_t | n, |
int_t | e | ||
) | [inline] |
Adds an element to the given set.
Definition at line 167 of file bitsets.h.
References bits, longBitMask, longBitShift, and nunits.
void chomp::homology::BitSets::addset | ( | int_t | n, |
int_t | m | ||
) | [inline] |
int_t chomp::homology::BitSets::arraySize | ( | ) | [inline, private] |
bool chomp::homology::BitSets::check | ( | int_t | n, |
int_t | e | ||
) | const [inline] |
Checks if an element belongs to the given set.
Definition at line 182 of file bitsets.h.
References bits, longBitMask, longBitShift, and nunits.
int_t chomp::homology::BitSets::get | ( | int_t | n, |
int_t | start = 0 |
||
) | const [inline] |
Retrieves an element >= 'start' in the given set.
Returns -1 if none.
Definition at line 197 of file bitsets.h.
References bits, longBitMask, longBits, longBitShift, nelem, and nunits.
void chomp::homology::BitSets::remove | ( | int_t | n, |
int_t | e | ||
) | [inline] |
Removes an element from the given set.
Definition at line 175 of file bitsets.h.
References bits, longBitMask, longBitShift, and nunits.
unsigned long* chomp::homology::BitSets::bits [private] |
The memory buffer for storing the bits.
Definition at line 107 of file bitsets.h.
Referenced by add(), addset(), BitSets(), check(), get(), operator=(), remove(), and ~BitSets().
const int_t chomp::homology::BitSets::longBitMask = longBits - 1 [static, private] |
const int_t chomp::homology::BitSets::longBits = sizeof (long) * 8 [static, private] |
const int_t chomp::homology::BitSets::longBitShift = (sizeof (long) == 8) ? 6 : 5 [static, private] |
int_t chomp::homology::BitSets::nelem [private] |
The maximal number of elements in each set.
Definition at line 101 of file bitsets.h.
Referenced by get(), and operator=().
int_t chomp::homology::BitSets::nsets [private] |
The number of sets.
Definition at line 98 of file bitsets.h.
Referenced by arraySize(), and operator=().
int_t chomp::homology::BitSets::nunits [private] |
The number of array entries used for each set.
Definition at line 104 of file bitsets.h.
Referenced by add(), addset(), arraySize(), check(), get(), operator=(), and remove().