The Original CHomP Software
|
This class defines a bit field that is part of some larger array or that uses an allocated piece of memory. More...
#include <bitfield.h>
Public Member Functions | |
BitField () | |
The constructor of an undefined bit field. More... | |
~BitField () | |
The destructor which actually does nothing. More... | |
bool | defined () const |
Returns true if the bit field has already been defined, that is, it is bound with some memory piece, or its memory has been allocated. More... | |
void | define (unsigned char *buf, int_t length) |
Define the bit field as a piece of a larger memory buffer. More... | |
void | allocate (int_t length) |
Allocates memory for a bit field. More... | |
void | free () |
Releases the memory allocated for the bit field. More... | |
void | set (int_t n) |
Sets the given bit to 1. More... | |
void | clear (int_t n) |
Clears the given bit (sets it to 0). More... | |
int | test (int_t n) const |
Tests the given bit. Returns 0 or 1. More... | |
void | takebits (const BitField &from, int_t length) |
Copies all the bits from the given bitfield. More... | |
void | clearall (int_t length) |
Clears all the bits in the entire bit field of specified length. More... | |
int | find (int_t first, int_t length) const |
Finds the first bit that is set to 1, beginning at the given one. More... | |
int_t | hashkey (int_t length) const |
Returns the first key for hashing. More... | |
int_t | hashadd (int_t length) const |
Returns the second key for hashing. More... | |
Private Attributes | |
unsigned char * | table |
The table of 8-bit cells which store the subsequent bits. More... | |
Friends | |
bool | thesame (const BitField &b1, const BitField &b2, int_t length) |
Compares two bit fields of the giben length. More... | |
void | int2bits (int bits, int_t length, BitField &field) |
Converts an integer into the bits of a bit field of the given length. More... | |
int | bits2int (const BitField &field, int_t length) |
Converts the bits of a bit field of the given length into an integer. More... | |
This class defines a bit field that is part of some larger array or that uses an allocated piece of memory.
This class may be useful for efficient management of multiple bit fields, or just one bit field. Note the very specific behavior of memory management!
Definition at line 72 of file bitfield.h.
|
inline |
The constructor of an undefined bit field.
Definition at line 161 of file bitfield.h.
References table.
|
inline |
The destructor which actually does nothing.
Definition at line 179 of file bitfield.h.
void chomp::homology::BitField::allocate | ( | int_t | length | ) |
Allocates memory for a bit field.
The memory enough to store the given number of bits (the length of the bit field) is allocated with the 'new' operator. The allocated memory is filled with zeros, which isequivalent to calling the clearall procedure.
|
inline |
Clears the given bit (sets it to 0).
Definition at line 190 of file bitfield.h.
References table.
void chomp::homology::BitField::clearall | ( | int_t | length | ) |
Clears all the bits in the entire bit field of specified length.
Note that the bit field itself does not store its length.
void chomp::homology::BitField::define | ( | unsigned char * | buf, |
int_t | length | ||
) |
Define the bit field as a piece of a larger memory buffer.
The memory enough to store the given number of bits (the length of the bit field) will be used.
|
inline |
Returns true if the bit field has already been defined, that is, it is bound with some memory piece, or its memory has been allocated.
Definition at line 167 of file bitfield.h.
References table.
Finds the first bit that is set to 1, beginning at the given one.
Return the number of the bit, or -1 if not found. Note that the bit field itself does not store its length, so this length must be provided as an argument of this function.
|
inline |
Releases the memory allocated for the bit field.
This must be used if the memory was allocated, because the destructor does not deallocte the memory.
Definition at line 172 of file bitfield.h.
References table.
Returns the second key for hashing.
Note that the bit field itself does not store its length, so this length must be provided as an argument of this function.
Returns the first key for hashing.
Note that the bit field itself does not store its length, so this length must be provided as an argument of this function.
|
inline |
Sets the given bit to 1.
Definition at line 184 of file bitfield.h.
References table.
Copies all the bits from the given bitfield.
Assumes that both bit fields have the specified length. Note that the bit field itself does not store its length.
|
inline |
Converts the bits of a bit field of the given length into an integer.
The length must not exceed the size of the integer.
Definition at line 215 of file bitfield.h.
Converts an integer into the bits of a bit field of the given length.
The length must not exceed the size of the integer.
Definition at line 201 of file bitfield.h.
Compares two bit fields of the giben length.
Returns true if they are the same, false otherwise.
|
private |
The table of 8-bit cells which store the subsequent bits.
It is either an address of some allocated memory, or an address of portion of some other memory, for example, allocated collectively for a large number of bit fields.
Definition at line 155 of file bitfield.h.
Referenced by BitField(), clear(), defined(), free(), set(), and test().