34#ifndef _CHOMP_STRUCT_BITSETS_H_
35#define _CHOMP_STRUCT_BITSETS_H_
117 long size =
static_cast<long> (
nsets) *
static_cast<long> (
nunits);
118 if (
static_cast<long> (
static_cast<int_t> (size)) != size)
119 throw "Too large BitSets requested.";
120 return static_cast<int_t> (size);
124 nsets (_nsets), nelem (_nelem),
125 nunits ((_nelem + (sizeof (unsigned long) << 3) - 1) /
126 (sizeof (unsigned long) << 3)), bits (0)
129 bits =
new unsigned long [size];
130 for (
int_t i = 0; i < size; ++ i)
136 nsets (s. nsets), nelem (s. nelem), nunits (s. nunits), bits (0)
139 bits =
new unsigned long [size];
140 for (
int_t i = 0; i < size; ++ i)
154 bits =
new unsigned long [size];
155 for (
int_t i = 0; i < size; ++ i)
192 *(nbuf ++) |= *(mbuf ++);
203 if (buf [offset] & (~0ul << bit))
207 if (buf [offset] & (1ul << bit))
210 throw "Wrong bit number in BitSets.";
212 for (++ offset; offset <
nunits; ++ offset)
216 for (
int bit = 0; bit <
longBits; ++ bit)
218 if (buf [offset] & (1ul << bit))
221 throw "False bit in BitSets.";
This class uses bit representation to store many small sets.
int_t nunits
The number of array entries used for each set.
unsigned long * bits
The memory buffer for storing the bits.
void addset(int_t n, int_t m)
Adds the entire set 'm' to the set 'n'.
void remove(int_t n, int_t e)
Removes an element from the given set.
BitSets(int_t _nsets, int_t _nelem)
Constructor of a family of empty sets.
int_t arraySize()
Computes the size of the memory array for storing the bits.
int_t nelem
The maximal number of elements in each set.
static const int_t longBitMask
BitSets & operator=(const BitSets &s)
Assignment operator.
static const int_t longBitShift
bool check(int_t n, int_t e) const
Checks if an element belongs to the given set.
static const int_t longBits
void add(int_t n, int_t e)
Adds an element to the given set.
int_t get(int_t n, int_t start=0) const
Retrieves an element >= 'start' in the given set.
int_t nsets
The number of sets.
This file contains some precompiler definitions which indicate the operating system and/or compiler u...
int int_t
Index type for indexing arrays, counting cubes, etc.
This namespace contains the entire CHomP library interface.