Bit stream struct.
More...
#include <BitStream.h>
|
| BitStream () |
| Default constructor for ROOT.
|
|
| BitStream (int n) |
| Constructor with the reserved and cleared storage prepared for incoming bits.
|
|
void | putNBits (unsigned int value, unsigned int n) |
| Push n least significant bits of "value" to the stream.
|
|
unsigned int | getNBits (unsigned int n) |
| Fetch n bits.
|
|
size_t | getPos () const |
| Get current position in the stream.
|
|
void | setPos (size_t pos) |
| Set position in the stream.
|
|
std::vector< unsigned int > & | getStore () |
| Get data vector.
|
|
void | resize () |
| Resize data vector to the current position.
|
|
|
size_t | m_pos |
| Current position in the storage.
|
|
std::vector< unsigned int > | m_store |
| The bit storage.
|
|
Bit stream struct.
Class contains vector of unsigned ints as a storage and current bit position in the storage. One can put and fetch up to 32 bits at once.
Definition at line 19 of file BitStream.h.
◆ BitStream() [1/2]
Default constructor for ROOT.
Current position is at beginning of the storage.
Definition at line 24 of file BitStream.h.
24: m_pos(0), m_store(1, 0) {}
◆ BitStream() [2/2]
Constructor with the reserved and cleared storage prepared for incoming bits.
Be sure the size is enough for incoming data since the class does not check bounds. Current position is at beginning of the storage.
Definition at line 31 of file BitStream.h.
31: m_pos(0), m_store(n, 0) {}
◆ getNBits()
unsigned int getNBits |
( |
unsigned int | n | ) |
|
|
inline |
Fetch n bits.
Update current position accordingly
- Parameters
-
n | – how many bits fetch from the current position in the stream |
- Returns
- n fetched bits
Definition at line 52 of file BitStream.h.
53 {
54 unsigned int bpos = m_pos % 32, wpos = m_pos / 32;
55
56 if (
branch_unlikely(m_pos + n > m_store.size() * 32))
throw std::range_error(
"Not enough bits in stream");
57 unsigned int res = m_store[wpos] >> bpos;
58 if (bpos + n > 32) res |= m_store[wpos + 1] << (32 - bpos);
59 m_pos += n;
60 return res & (0xffffffffu >> (32 - n));
61 }
#define branch_unlikely(x)
A macro to tell the compiler that the argument x will be very likely be false.
◆ getPos()
Get current position in the stream.
Definition at line 64 of file BitStream.h.
◆ getStore()
std::vector< unsigned int > & getStore |
( |
| ) |
|
|
inline |
◆ putNBits()
void putNBits |
( |
unsigned int | value, |
|
|
unsigned int | n ) |
|
inline |
Push n least significant bits of "value" to the stream.
Update current position accordingly.
- Parameters
-
value | – value to put in the stream |
n | – how many least signfificant bits of "value" put in the stream (n<=32) |
Definition at line 37 of file BitStream.h.
38 {
39 unsigned int bpos = m_pos % 32, wpos = m_pos / 32;
40 value &= 0xffffffffu >> (32 - n);
41
42 if (
branch_unlikely(m_pos + n > m_store.size() * 32)) m_store.resize(2 * m_store.size(), 0);
43 m_store[wpos] |= value << bpos;
44 if (bpos + n > 32) m_store[wpos + 1] = value >> (32 - bpos);
45 m_pos += n;
46 }
◆ resize()
Resize data vector to the current position.
Definition at line 73 of file BitStream.h.
74 {
75 m_store.resize((m_pos + 31) / 32);
76 }
◆ setPos()
void setPos |
( |
size_t | pos | ) |
|
|
inline |
Set position in the stream.
Definition at line 67 of file BitStream.h.
◆ m_pos
Current position in the storage.
Definition at line 78 of file BitStream.h.
◆ m_store
std::vector<unsigned int> m_store |
|
protected |
The documentation for this class was generated from the following file: