#include <tlbitfield.h>
Collaboration diagram for TLStaticBitField< T, N >:
Public Types | |
typedef uint | nents_t |
Public Member Functions | |
TLStaticBitField () | |
Creates an uninitialized bitfield. | |
TLStaticBitField (bool bitval) | |
Creates a bitfield with all elements set to passed value. | |
TLStaticBitField (const TLStaticBitField< T, N > &b) | |
Creates a copy of the passed bitfield. | |
~TLStaticBitField () | |
Destructor is a no-op. | |
TLStaticBitField & | operator= (const TLStaticBitField< T, N > &b) |
Assignment operator: copy bit values:. | |
void | SetBit (size_t bit) |
Set a bit; bit in range 0..N-1; no range check! | |
void | ClrBit (size_t bit) |
Clear a bit; bit in range 0..N-1; no range check! | |
bool | GetBit (size_t bit) |
Query a bit value; bit in range 0..N-1; no range check! | |
void | AssBit (size_t bit, bool val) |
Assign bit value; bit in range 0..N-1; no range check! | |
void | SetAll () |
Set all bits (to 1). | |
void | ClrAll () |
Clear all bits (to 0). | |
size_t | CountSet () |
Count number of bits set. | |
size_t | CountClr () |
Count number of bits not set. | |
ssize_t | SearchFirstSet () |
Search bit address of first set (1) bit in bitfield. | |
ssize_t | SearchFirstClr () |
Search bit address of first cleared (0) bit in bitfield. | |
Private Member Functions | |
void | _SetAllEnts (T val) |
Used to set/clear _all_ bits. | |
void | _CopyFrom (const TLStaticBitField< T, N > &b) |
Copy bit field content. | |
Private Attributes | |
T | bits [nents] |
The actual bitfield array. | |
Static Private Attributes | |
const nents_t | nents = (N+8*sizeof(T)-1)/(8*sizeof(T)) |
Number of entries in the bitfield array. | |
const T | band = T(8*sizeof(T)-1) |
AND mask for part of bit address stored inside one entry. | |
const int | bshift |
Number of bits to shift left to get entry index from bit address. | |
const size_t | bits_per_ent = 8*sizeof(T) |
Number of bits per entry:. | |
const T | exmask |
This mask contains all excess (unused) bits in bits[nents-1]. | |
const T | all_clr = T(0) |
Constant of type T with all bits cleared. | |
const T | all_set = ~all_clr |
Constant of type T with all bits set. | |
Friends | |
int | DoTestBitFields () |
This is the fastest version of all the bitfield templates available in this file.
Template parameters:
T: Type to use for bit storage. Recommend one word on the underlying architecture; probably size_t is a good choice.
N: Number of bits to be stored in the bitfield.
This class is "C++-safe"; assignent and copy constructor will copy the bitfield data.
Definition at line 136 of file tlbitfield.h.
|
Type for the number of entries; must be capable of representing N/(8*sizeof(T)). Definition at line 142 of file tlbitfield.h. Referenced by TLStaticBitField< T, N >::_CopyFrom(), TLStaticBitField< T, N >::_SetAllEnts(), TLStaticBitField< T, N >::CountClr(), TLStaticBitField< T, N >::CountSet(), TLStaticBitField< T, N >::SearchFirstClr(), and TLStaticBitField< T, N >::SearchFirstSet(). |
|
Creates an uninitialized bitfield.
Definition at line 182 of file tlbitfield.h. |
|
Creates a bitfield with all elements set to passed value.
Definition at line 184 of file tlbitfield.h. References TLStaticBitField< T, N >::_SetAllEnts(), TLStaticBitField< T, N >::all_clr, and TLStaticBitField< T, N >::all_set. |
|
Creates a copy of the passed bitfield.
Definition at line 187 of file tlbitfield.h. References TLStaticBitField< T, N >::_CopyFrom(). |
|
Destructor is a no-op.
Definition at line 190 of file tlbitfield.h. |
|
Copy bit field content.
For internal use only.
Definition at line 177 of file tlbitfield.h. References TLStaticBitField< T, N >::bits, TLStaticBitField< T, N >::nents, and TLStaticBitField< T, N >::nents_t. Referenced by TLStaticBitField< T, N >::operator=(), and TLStaticBitField< T, N >::TLStaticBitField(). |
|
Used to set/clear _all_ bits.
For internal use only.
Definition at line 174 of file tlbitfield.h. References TLStaticBitField< T, N >::bits, TLStaticBitField< T, N >::nents, and TLStaticBitField< T, N >::nents_t. Referenced by TLStaticBitField< T, N >::ClrAll(), TLStaticBitField< T, N >::SetAll(), and TLStaticBitField< T, N >::TLStaticBitField(). |
|
Assign bit value; bit in range 0..N-1; no range check!
Definition at line 206 of file tlbitfield.h. References TLStaticBitField< T, N >::ClrBit(), and TLStaticBitField< T, N >::SetBit(). Referenced by DoTestBitFields(). |
|
Clear all bits (to 0).
Definition at line 213 of file tlbitfield.h. References TLStaticBitField< T, N >::_SetAllEnts(), and TLStaticBitField< T, N >::all_clr. Referenced by DoTestBitFields(). |
|
Clear a bit; bit in range 0..N-1; no range check!
Definition at line 200 of file tlbitfield.h. References TLStaticBitField< T, N >::band, TLStaticBitField< T, N >::bits, and TLStaticBitField< T, N >::bshift. Referenced by TLStaticBitField< T, N >::AssBit(), and DoTestBitFields(). |
|
Count number of bits not set.
Definition at line 226 of file tlbitfield.h. References TLStaticBitField< T, N >::bits, CountBitsCleared(), TLStaticBitField< T, N >::exmask, TLStaticBitField< T, N >::nents, and TLStaticBitField< T, N >::nents_t. |
|
Count number of bits set.
Definition at line 217 of file tlbitfield.h. References TLStaticBitField< T, N >::bits, CountBitsSet(), TLStaticBitField< T, N >::exmask, TLStaticBitField< T, N >::nents, and TLStaticBitField< T, N >::nents_t. Referenced by DoTestBitFields(). |
|
Query a bit value; bit in range 0..N-1; no range check!
Definition at line 203 of file tlbitfield.h. References TLStaticBitField< T, N >::band, TLStaticBitField< T, N >::bits, and TLStaticBitField< T, N >::bshift. Referenced by DoTestBitFields(). |
|
Assignment operator: copy bit values:.
Definition at line 193 of file tlbitfield.h. References TLStaticBitField< T, N >::_CopyFrom(). |
|
Search bit address of first cleared (0) bit in bitfield.
Definition at line 253 of file tlbitfield.h. References TLStaticBitField< T, N >::all_set, TLStaticBitField< T, N >::bits, TLStaticBitField< T, N >::bits_per_ent, TLStaticBitField< T, N >::exmask, TLStaticBitField< T, N >::nents, TLStaticBitField< T, N >::nents_t, SearchFirstClearedBit(), and ssize_t. Referenced by DoTestBitFields(). |
|
Search bit address of first set (1) bit in bitfield.
Definition at line 239 of file tlbitfield.h. References TLStaticBitField< T, N >::all_clr, TLStaticBitField< T, N >::bits, TLStaticBitField< T, N >::bits_per_ent, TLStaticBitField< T, N >::exmask, TLStaticBitField< T, N >::nents, TLStaticBitField< T, N >::nents_t, SearchFirstSetBit(), and ssize_t. Referenced by DoTestBitFields(). |
|
Set all bits (to 1).
Definition at line 210 of file tlbitfield.h. References TLStaticBitField< T, N >::_SetAllEnts(), and TLStaticBitField< T, N >::all_set. Referenced by DoTestBitFields(). |
|
Set a bit; bit in range 0..N-1; no range check!
Definition at line 197 of file tlbitfield.h. References TLStaticBitField< T, N >::band, TLStaticBitField< T, N >::bits, and TLStaticBitField< T, N >::bshift. Referenced by TLStaticBitField< T, N >::AssBit(), and DoTestBitFields(). |
|
Definition at line 23 of file test-bitfield.cc. |
|
Constant of type T with all bits cleared.
Definition at line 166 of file tlbitfield.h. Referenced by TLStaticBitField< T, N >::ClrAll(), TLStaticBitField< T, N >::SearchFirstSet(), and TLStaticBitField< T, N >::TLStaticBitField(). |
|
Constant of type T with all bits set.
Definition at line 168 of file tlbitfield.h. Referenced by TLStaticBitField< T, N >::SearchFirstClr(), TLStaticBitField< T, N >::SetAll(), and TLStaticBitField< T, N >::TLStaticBitField(). |
|
AND mask for part of bit address stored inside one entry.
Definition at line 148 of file tlbitfield.h. Referenced by TLStaticBitField< T, N >::ClrBit(), DoTestBitFields(), TLStaticBitField< T, N >::GetBit(), and TLStaticBitField< T, N >::SetBit(). |
|
The actual bitfield array.
Definition at line 171 of file tlbitfield.h. Referenced by TLStaticBitField< T, N >::_CopyFrom(), TLStaticBitField< T, N >::_SetAllEnts(), TLStaticBitField< T, N >::ClrBit(), TLStaticBitField< T, N >::CountClr(), TLStaticBitField< T, N >::CountSet(), TLStaticBitField< T, N >::GetBit(), TLStaticBitField< T, N >::SearchFirstClr(), TLStaticBitField< T, N >::SearchFirstSet(), and TLStaticBitField< T, N >::SetBit(). |
|
Number of bits per entry:.
Definition at line 157 of file tlbitfield.h. Referenced by TLStaticBitField< T, N >::SearchFirstClr(), and TLStaticBitField< T, N >::SearchFirstSet(). |
|
Initial value: sizeof(T)==1 ? 3 : sizeof(T)==2 ? 4 : sizeof(T)==4 ? 5 : sizeof(T)==8 ? 6 : sizeof(T)==16 ? 7 : 8
Definition at line 150 of file tlbitfield.h. Referenced by TLStaticBitField< T, N >::ClrBit(), DoTestBitFields(), TLStaticBitField< T, N >::GetBit(), and TLStaticBitField< T, N >::SetBit(). |
|
Initial value: ( (N % (8*sizeof(T)))==0 ) ?
T(0) : ~((T(1)<<(N % (8*sizeof(T))))-1)
Definition at line 162 of file tlbitfield.h. Referenced by TLStaticBitField< T, N >::CountClr(), TLStaticBitField< T, N >::CountSet(), DoTestBitFields(), TLStaticBitField< T, N >::SearchFirstClr(), and TLStaticBitField< T, N >::SearchFirstSet(). |
|
Number of entries in the bitfield array.
Definition at line 146 of file tlbitfield.h. Referenced by TLStaticBitField< T, N >::_CopyFrom(), TLStaticBitField< T, N >::_SetAllEnts(), TLStaticBitField< T, N >::CountClr(), TLStaticBitField< T, N >::CountSet(), DoTestBitFields(), TLStaticBitField< T, N >::SearchFirstClr(), and TLStaticBitField< T, N >::SearchFirstSet(). |