#ifndef BIT_BUFFER_H
#define BIT_BUFFER_H
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <vector>
namespace speck {
class bit_buffer {
public:
void reserve(size_t);
void clear() noexcept;
auto empty() const noexcept -> bool;
auto size() const noexcept -> size_t;
void push_back(bool);
auto data() const noexcept -> const uint8_t*;
auto data_size() const noexcept -> size_t;
auto peek(size_t) const -> bool;
auto par_peek(size_t) const -> bool;
auto populate(const void* memory, size_t mem_len, size_t num_bits) -> bool;
private:
mutable std::vector<uint8_t> m_vec;
size_t m_total_bits = 0;
mutable uint8_t m_cache[8];
mutable size_t m_cache_full = 0;
mutable size_t m_cache_vec_pos = 0;
void m_flush_cache() const;
const uint64_t MAGIC = 0x8040201008040201;
const uint64_t MASK = 0x8080808080808080;
};
};
#endif