BitList.h



Classes

BitList -- BitList class (full description)
BitListIterator -- BitListIterator class (full description)

class BitList

Interface

Public Members
BitList(size_t size = 0, size_t inc = 0)
BitList(const BitList &)
BitList & operator = (const BitList &)
void set(size_t index, bool value)
bool operator [](size_t) const
size_t size() const
size_t count() const
size_t trim()
void clear(bool keepLength = false)
BitList & operator &= (const BitList &)
BitList & operator |= (const BitList &)
void invert()
bool covers(const BitList & BL) const
bool overlaps(const BitList & BL) const
void compress(ostream &) const
void decompress(istream &)
Private Members
friend BitList & and (BitList &, const BitList &, const BitList &)
friend BitList & or (BitList &, const BitList &, const BitList &)
friend BitList & xor (BitList &, const BitList &, const BitList &)
friend BitList & not (BitList &, const BitList &)
void choplitter_()

Description

The BitList is an array of bits. A bit can be set at any index using the set member function, the array expands itself automatically if the index exceeds the current size.

Member Description

BitList(size_t size = 0, size_t inc = 0)

Default constructor, you can initialize the BitList to a specific size and optionally the increment may be set by which the size internal ValVec will be incremented upon need. (See VarVec.h for explanation on this.) The default is to double the size of the array whenever an expansion is requested.

BitList(const BitList &)

Copy constructor

BitList & operator = (const BitList &)

The assignment operator.

void set(size_t index, bool value)

Set a bit at a specific index to a given value. If the index is larger than the current size, the BitList expands itself to be able to hold that value at the given index.

bool operator [](size_t) const

Get the bit at a given index. If the index exceeds the size, the return value is 'false'. All BitLists are treated as if they were of infinite size, all bits set to zero at initialization.

size_t size() const

Get the size of the BitList. At construction time the size may be specified, and that much memory will be allocated. If the construction is done using the set() method, the size is 'minimal' i.e. as much as it needs to hold the last 'true' bit.

size_t count() const

Count the TRUE bits from a certain index on

size_t trim()

Just chop off all trailing 'false' bits. Returns new size.

void clear(bool keepLength = false)

Clear the list, reset size to 0 by default. If true is given as an argument, the size is kept.

BitList & operator &= (const BitList &)

The standard &= operator.

BitList & operator |= (const BitList &)

The standard |= operator.

void invert()

The inversion method, flip every bit in the BitList.

bool covers(const BitList & BL) const

Check if BL is a subset of the current list

bool overlaps(const BitList & BL) const

Check if the current BitList overlaps with the other (i.e. they have at least one common Bit)

void compress(ostream &) const

compress output

void decompress(istream &)

decompress input

friend BitList & and (BitList &, const BitList &, const BitList &)

friend BitList & or (BitList &, const BitList &, const BitList &)

friend BitList & xor (BitList &, const BitList &, const BitList &)

friend BitList & not (BitList &, const BitList &)

void choplitter_()

Mask off litter at the end of a word not belonging to the array


class BitListIterator

Interface

Public Members
BitListIterator()
BitListIterator(const BitList & bitlist)
BitListIterator(const BitList & bitlist, size_t start)
BitListIterator(const BitListIterator &)
BitListIterator & operator = (const BitListIterator &)
void setindex(size_t index)
bool next(bool bit, size_t & _index)
bool prev(bool bit, size_t & _index)
bool next(bool & bit)
bool prev(bool & bit)
Private Members
bool incr()
bool decr()

Description

The BitListIterator iterates through a BitList efficiently. next() and prev() functions are supplied. The functionality is the following: The BLI saves an index to a certain bit in the BitList. By calling either next() or prev(), the index is incremented/decremented and the bit it is pointing to now is returned. If it gets out of bounds, these functions return 'false'. The out-of-bounds index is always index=size. So by calling next() or prev() again when a 'false' was returned previously, they return the first/last bit, respectively.

Member Description

BitListIterator()

Default Constructor.

BitListIterator(const BitList & bitlist)

Normal Constructor: needs the BitList to initialize. The index is initialized to the out-of-bounds index.

BitListIterator(const BitList & bitlist, size_t start)

Alternate constructor: set the starting index yourself.

BitListIterator(const BitListIterator &)

Copy Constructor.

BitListIterator & operator = (const BitListIterator &)

Assignment.

void setindex(size_t index)

Init: set current index

bool next(bool bit, size_t & _index)

Set the internal index to the next 'true' or 'false' bit, indicated by the first argument, and return the index in the second argument. Returns 'false' if it gets out of bounds. Example: For a BitList 001100110011 (from left to right, index starts at 0), the subsequent call to next(true,index) returns 'true' and sets index to 2, 3, 6, 7, 10, 11. The next call puts leaves index and returns 'false'. A subsequent next() call would again return 'true' and set index=2.

bool prev(bool bit, size_t & _index)

Just like next(), but the index is moved backwards.

bool next(bool & bit)

Increment the internal index and put the value of the bit it points to into bit. Returns 'false' if the boundary is reached. Example: For a BitList 001100110011 the calls to next(val) return 'true' and set bit to 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1. The next call returns 'false' and does not set bit. A subsequent call would return again 'true' and set bit to the first bit in the list, in this case 0.

bool prev(bool & bit)

Just like next() above, just decrement the internal index. The two versions of next() and prev() may be used in conjunction.

bool incr()

increment, decrement current index, return 'true' or 'false' if boundary has been reached

bool decr()


© Copyright The Johns Hopkins University 1999, All Rights Reserved.
Peter Z. Kunszt,