12 std::vector<uint64_t> data_;
15 OutputBitStream() : size_(0) {}
21 if (size_ % 64 == 0) {
24 data_.back() |= 1ull << (size_ % 64);
33 template <std::
integral T>
35 using UT = std::make_unsigned_t<T>;
36 UT ubits =
static_cast<UT
>(bits);
37 constexpr size_t length =
sizeof(T) * 8;
38 static_assert(length <= 64);
39 if (size_ % 64 == 0) {
40 data_.push_back(ubits);
42 const size_t prefix = std::min(length, 64 - (size_ % 64));
43 data_.back() |=
static_cast<uint64_t
>(ubits & ((1ull << prefix) - 1))
45 if (prefix < length) {
46 data_.push_back(ubits >> prefix);
57 size_t size()
const {
return size_; }
69 std::vector<uint64_t>
extract() {
return std::move(data_); }
size_t size() const
Returns the number of written bits.
Definition bit_stream.h:57
std::vector< uint64_t > extract()
Moves vector containing written bits. There must be no operator<< after extract()
Definition bit_stream.h:69
OutputBitStream & operator<<(T bits)
Writes bits of the integral number to the stream in little-endian.
Definition bit_stream.h:34
OutputBitStream & operator<<(bool bit)
Writes one bit to the stream.
Definition bit_stream.h:20
void reserve(size_t size)
Reserves memory for "size" bits.
Definition bit_stream.h:63