MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
|
#include <BitVector.h>
Public Types | |
enum | { BITS = B } |
typedef u32 | BitUnitType |
Public Member Functions | |
u32 | GetLength () const |
void | WriteBit (u32 idx, bool bit) |
bool | ReadBit (u32 idx) |
BitVector () | |
BitVector (const BitVector &other) | |
BitVector (const u32 *const values) | |
u32 | Read (const u32 startIdx, const u32 length) const |
void | Write (const u32 startIdx, const u32 length, const u32 value) |
u64 | ReadLong (const u32 startIdx, const u32 length) const |
void | WriteLong (const u32 startIdx, const u32 length, const u64 value) |
void | SetBit (const u32 idx) |
void | ClearBit (const u32 idx) |
bool | ReadBit (const u32 idx) const |
bool | ToggleBit (const u32 idx) |
void | SetBits (const u32 startIdx, const u32 length) |
void | ClearBits (const u32 startIdx, const u32 length) |
void | StoreBits (const u32 bits, const u32 startIdx, const u32 length) |
void | Clear () |
void | Print (ByteSink &ostream) const |
void | PrintBinary (ByteSink &ostream) const |
bool | Read (ByteSource &bs) |
bool | ReadBinary (ByteSource &bs) |
bool | operator== (const BitVector &rhs) const |
Static Public Attributes | |
static const u32 | BITS_PER_UNIT = sizeof(BitUnitType) * CHAR_BIT |
static const u32 | ARRAY_LENGTH = (BITS + BITS_PER_UNIT - 1) / BITS_PER_UNIT |
A bit vector with reasonably fast operations
BITS should be a multiple of BITS_PER_UNIT (currently 32). Otherwise there will, at least, be some wasted space – and may be other issues.
MFM::BitVector< BITS >::BitVector | ( | ) |
MFM::BitVector< BITS >::BitVector | ( | const BitVector< B > & | other | ) |
MFM::BitVector< BITS >::BitVector | ( | const u32 *const | values | ) |
void MFM::BitVector< BITS >::Clear | ( | ) |
Sets all bits of this BitVector to 0
.
|
inline |
Clears the bit at a specified index in this BitVector.
idx | The index of the bit to clear, where the MSB is indexed at 0 . |
|
inline |
Clear a contiguous range of bits, so they all have value 0.
|
inline |
void MFM::BitVector< BITS >::Print | ( | ByteSink & | ostream | ) | const |
void MFM::BitVector< BITS >::PrintBinary | ( | ByteSink & | ostream | ) | const |
|
inline |
Reads up to 32 bits of a particular section of this BitVector.
startIdx | The index of the first bit to read inside this BitVector, where the MSB is indexed at 0 . |
length | The number of bits to read from this BitVector. This should be in the range [1,32] . |
bool MFM::BitVector< BITS >::Read | ( | ByteSource & | bs | ) |
Load this BitVector from a specified ByteSource by reading BITS / 4 bytes in hex format. Skips leading whitespace. Returns true
if all went well; returns false if insufficient consecutive hex bytes were available to fully initialize the BitVector . When false is returned the ByteSource will be positioned just before the first unacceptable byte encountered, and the BitVector will be unchanged.
istream | The ByteSource to read bytes from. |
true
if all went well, else false
. bool MFM::BitVector< BITS >::ReadBinary | ( | ByteSource & | bs | ) |
Load this BitVector from a specified ByteSource by reading BITS bytes in binary format. Skips leading whitespace. Returns true
if all went well; returns false
if insufficient consecutive binary bytes were available to fully initialize the BitVector . When false
is returned, the ByteSource will be positioned just before the first unacceptable byte encountered, and the BitVector will be unchanged.
istream | The ByteSource to read bytes from. |
true
if all went well, else false
. bool MFM::BitVector< BITS >::ReadBit | ( | u32 | idx | ) |
Reads a specified value from a particular bit in this BitVector.
idx | The bit to read, where the MSB is index 0. |
idx
index.
|
inline |
Reads a single bit at a specified index from this BitVector.
idx | The index of the bit to read. |
1
if this bit is set, else 0
.
|
inline |
Reads up to 64 bits of a particular section of this BitVector.
startIdx | The index of the first bit to read inside this BitVector, where the MSB is indexed at 0 . |
length | The number of bits to read from this BitVector. This should be in the range [0,64] . |
|
inline |
Sets the bit at a specified index in this BitVector.
idx | The index of the bit to set, where the MSB is indexed at 0 . |
|
inline |
Set a contiguous range of bits, so they all have value 1.
void MFM::BitVector< BITS >::StoreBits | ( | const u32 | bits, |
const u32 | startIdx, | ||
const u32 | length | ||
) |
Store a bit value (or pattern) into a contiguous range of bits, so they all have that value.
bits | The bits to store. The supplied bits are tiled onto the contiguous range of bits as many times as needed to cover the given length, with the u32 bits aligned to the underlying u32 storage units. To avoid confusion, pass only 0x0 or 0xffffffff as bits. |
startIdx | The index of the first bit to store inside this BitVector, where the MSB is indexed at 0 . |
length | The number of bits to store in this BitVector. If this length would exceed the number of bits in the BitVector, the excess length is ignored. |
bool MFM::BitVector< BITS >::ToggleBit | ( | const u32 | idx | ) |
Flips the bit at a specified index in this BitVector. (i.e. bv[idx] = !bv[idx])
idx | The index of the bit to toggle, where the MSB is indexed at 0 . |
void MFM::BitVector< BITS >::Write | ( | const u32 | startIdx, |
const u32 | length, | ||
const u32 | value | ||
) |
Writes up to 32 bits of a specified u32 to a section of this BitVector.
void MFM::BitVector< BITS >::WriteBit | ( | u32 | idx, |
bool | bit | ||
) |
Writes a specified value to a particular bit in this BitVector.
idx | The bit to set, where the MSB is index 0. |
bit | The value to set the bit at idx to. |
void MFM::BitVector< BITS >::WriteLong | ( | const u32 | startIdx, |
const u32 | length, | ||
const u64 | value | ||
) |
Writes up to 64 bits of a specified u64 to a section of this BitVector.