Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes

chomp::homology::BitSets Class Reference

This class uses bit representation to store many small sets. More...

#include <chomp/struct/bitsets.h>

List of all members.

Public Member Functions

 BitSets (int_t _nsets, int_t _nelem)
 Constructor of a family of empty sets.
 BitSets (const BitSets &s)
 Copy constructor.
BitSetsoperator= (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

Detailed Description

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.


Constructor & Destructor Documentation

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]

Copy constructor.

Definition at line 136 of file bitsets.h.

References arraySize(), and bits.

chomp::homology::BitSets::~BitSets (  ) [inline]

Destructor.

Definition at line 161 of file bitsets.h.

References bits.


Member Function Documentation

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]

Adds the entire set 'm' to the set 'n'.

Definition at line 188 of file bitsets.h.

References bits, and nunits.

int_t chomp::homology::BitSets::arraySize (  ) [inline, private]

Computes the size of the memory array for storing the bits.

Definition at line 116 of file bitsets.h.

References nsets, and nunits.

Referenced by BitSets(), and operator=().

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.

BitSets & chomp::homology::BitSets::operator= ( const BitSets s ) [inline]

Assignment operator.

Definition at line 146 of file bitsets.h.

References arraySize(), bits, nelem, nsets, 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.


Member Data Documentation

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]

Definition at line 61 of file bitsets.h.

Referenced by add(), check(), get(), and remove().

const int_t chomp::homology::BitSets::longBits = sizeof (long) * 8 [static, private]

Definition at line 60 of file bitsets.h.

Referenced by get().

const int_t chomp::homology::BitSets::longBitShift = (sizeof (long) == 8) ? 6 : 5 [static, private]

Definition at line 62 of file bitsets.h.

Referenced by add(), check(), get(), and remove().

The maximal number of elements in each set.

Definition at line 101 of file bitsets.h.

Referenced by get(), and operator=().

The number of sets.

Definition at line 98 of file bitsets.h.

Referenced by arraySize(), and operator=().

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().


The documentation for this class was generated from the following file: