This class uses bit representation to store many small sets. More...
#include <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 Attributes | |
int_t | nsets |
The number of sets. | |
int_t | nelem |
The maximal number of elements in each set. | |
int_t | nbytes |
The number of bytes used for each set. | |
unsigned char * | bits |
The memory buffer for storing the bits. |
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 | ( | const BitSets & | s | ) | [inline] |
chomp::homology::BitSets::~BitSets | ( | ) | [inline] |
Retrieves an element >= 'start' in the given set.
Returns -1 if none.
Definition at line 177 of file bitsets.h.
References bits, nbytes, and nelem.
{ if (start >= nelem) return -1; unsigned char *buf = bits + n * nbytes; int_t offset = start >> 3; int bit = start & 0x07; if (buf [offset] & (0xFF << bit)) { for (; bit < 8; ++ bit) { if (buf [offset] & (0x01 << bit)) return (offset << 3) + bit; } throw "Wrong bit number in BitSets."; } for (++ offset; offset < nbytes; ++ offset) { if (!buf [offset]) continue; for (int bit = 0; bit < 8; ++ bit) { if (buf [offset] & (0x01 << bit)) return (offset << 3) + bit; } throw "False bit in BitSets."; } return -1; } /* BitSets::get */
unsigned char* chomp::homology::BitSets::bits [private] |
The memory buffer for storing the bits.
Definition at line 102 of file bitsets.h.
Referenced by add(), addset(), BitSets(), check(), get(), operator=(), remove(), and ~BitSets().
int_t chomp::homology::BitSets::nbytes [private] |
int_t chomp::homology::BitSets::nelem [private] |
The maximal number of elements in each set.
Definition at line 96 of file bitsets.h.
Referenced by get(), and operator=().
int_t chomp::homology::BitSets::nsets [private] |
The number of sets.
Definition at line 93 of file bitsets.h.
Referenced by BitSets(), and operator=().