#include <chomp/struct/bitfield.h>
Public Member Functions | |
BitField () | |
The constructor of an undefined bit field. | |
~BitField () | |
The destructor which actually does nothing. | |
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. | |
void | define (unsigned char *buf, int length) |
Define the bit field as a piece of a larger memory buffer. | |
void | allocate (int length) |
Allocates memory for a bit field. | |
void | free () |
Releases the memory allocated for the bit field. | |
void | set (int n) |
Sets the given bit to 1. | |
void | clear (int n) |
Clears the given bit (sets it to 0). | |
int | test (int n) const |
Tests the given bit. Returns 0 or 1. | |
void | takebits (const BitField &from, int length) |
Copies all the bits from the given bitfield. | |
void | clearall (int length) |
Clears all the bits in the entire bit field of specified length. | |
int | find (int after, int length) const |
Finds the first bit that is set to 1, beginning at the given one. | |
unsigned | hashkey (int length) const |
Returns the first key for hashing. | |
unsigned | hashadd (int length) const |
Returns the second key for hashing. | |
Private Attributes | |
unsigned char * | table |
The table of 8-bit cells which store the subsequent bits. | |
Friends | |
bool | thesame (const BitField &b1, const BitField &b2, int length) |
Compares two bit fields of the giben length. | |
void | int2bits (int bits, int length, BitField &field) |
Converts an integer into the bits of a bit field of the given length. | |
int | bits2int (const BitField &field, int length) |
Converts the bits of a bit field of the given length into an integer. |
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 73 of file bitfield.h.
chomp::homology::BitField::BitField | ( | ) | [inline] |
The constructor of an undefined bit field.
Definition at line 160 of file bitfield.h.
References table.
chomp::homology::BitField::~BitField | ( | ) | [inline] |
bool chomp::homology::BitField::defined | ( | ) | const [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 166 of file bitfield.h.
References table.
void chomp::homology::BitField::define | ( | unsigned char * | buf, | |
int | 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.
void chomp::homology::BitField::allocate | ( | int | 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.
void chomp::homology::BitField::free | ( | ) | [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 171 of file bitfield.h.
References table.
void chomp::homology::BitField::set | ( | int | n | ) | [inline] |
void chomp::homology::BitField::clear | ( | int | n | ) | [inline] |
int chomp::homology::BitField::test | ( | int | n | ) | const [inline] |
void chomp::homology::BitField::takebits | ( | const BitField & | from, | |
int | length | |||
) |
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.
void chomp::homology::BitField::clearall | ( | int | length | ) |
Clears all the bits in the entire bit field of specified length.
Note that the bit field itself does not store its length.
int chomp::homology::BitField::find | ( | int | after, | |
int | length | |||
) | const |
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.
unsigned chomp::homology::BitField::hashkey | ( | int | length | ) | const |
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.
unsigned chomp::homology::BitField::hashadd | ( | int | length | ) | const |
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.
Compares two bit fields of the giben length.
Returns true if they are the same, false otherwise.
void int2bits | ( | int | bits, | |
int | length, | |||
BitField & | field | |||
) | [friend] |
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 200 of file bitfield.h.
int bits2int | ( | const BitField & | field, | |
int | length | |||
) | [friend] |
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 214 of file bitfield.h.
unsigned char* chomp::homology::BitField::table [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 154 of file bitfield.h.
Referenced by BitField(), chomp::homology::bits2int(), clear(), defined(), free(), chomp::homology::int2bits(), set(), and test().