Skip to content

Commit

Permalink
use bitsize(), make things private again
Browse files Browse the repository at this point in the history
Change-Id: Ib720fb2b200a72d54bae4246a42524ec9b1444b7
  • Loading branch information
garymm committed Mar 10, 2024
1 parent 58f3d2e commit c4416b7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions huffman/src/bit_span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ namespace starflate::huffman {
/// A non-owning span of bits. Allows for iteration over the individual bits.
class bit_span : public std::ranges::view_interface<bit_span>
{

public:
// TODO: make private
const std::byte* data_{nullptr};
std::size_t bit_size_{};
std::uint8_t bit_offset_{}; // always less than CHAR_BIT

public:
/// An iterator over the bits in a bit_span.
class iterator : public detail::iterator_interface<iterator>
{
Expand Down
5 changes: 2 additions & 3 deletions huffman/src/decode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,21 @@ struct decode_result
/// @param bits The bit stream to decode.
///
/// @returns The decoded symbol and how many bits its code was.
/// If no symbol was found, result.encoded_size == 0.
/// @tparam Symbol The type of the symbols in the code table.
/// @tparam Extent The extent of the code table.
template <symbol Symbol, std::size_t Extent>
constexpr auto
decode_one(const table<Symbol, Extent>& code_table, bit_span bits)
-> decode_result<Symbol>
{
std::uint8_t bits_read{};
code current_code{};
auto code_table_pos = code_table.begin();
for (auto bit : bits) {
current_code << bit;
bits_read++;
auto found = code_table.find(current_code, code_table_pos);
if (found) {
return {(*found)->symbol, bits_read};
return {(*found)->symbol, (*found)->bitsize()};
}
if (found.error() == code_table.end()) {
break;
Expand Down

0 comments on commit c4416b7

Please sign in to comment.