17#ifndef RANS_INTERNAL_CONTAINERS_SYMBOL_H_
18#define RANS_INTERNAL_CONTAINERS_SYMBOL_H_
24#include <fairlogger/Logger.h>
41 :
mSymbol{frequency, cumulative} {};
59template <
typename source_T>
82 os << fmt::format(
"Symbol:{{Symbol: {}, Frequency: {}, Cumulative: {}}}",
107 assert(cumulative <=
utils::pow2(symbolTablePrecision));
108 assert(frequency <=
utils::pow2(symbolTablePrecision) - cumulative);
127 mFrequency = frequency;
156 mReciprocalFrequency =
static_cast<state_type>(~0ul);
157 mReciprocalShift = 0;
158 mCumulative = cumulative + (
utils::pow2(symbolTablePrecision)) - 1;
161 const uint32_t shift = std::ceil(std::log2(frequency));
166 uint64_t
x0 = frequency - 1;
167 const uint64_t
x1 = 1ull << (shift + 31);
169 const uint64_t
t1 =
x1 / frequency;
170 x0 += (
x1 % frequency) << 32;
171 const uint64_t
t0 =
x0 / frequency;
173 mReciprocalFrequency =
t0 + (
t1 << 32);
175 mReciprocalShift = shift - 1;
179 mCumulative = cumulative;
193 os << fmt::format(
"PrecomputedSymbol{{Frequency: {},Cumulative: {}, ReciprocalFrequency {}, FrequencyComplement {}, mReciprocalShift {}}}",
common helper classes and functions
constexpr const value_type & getDecoderSymbol() const noexcept
bool operator==(const DecoderSymbol &other) const
source_type mSourceSymbol
constexpr source_type getSourceSymbol() const noexcept
bool operator!=(const DecoderSymbol &other) const
constexpr DecoderSymbol(source_type symbol, typename value_type::value_type frequency, typename value_type::value_type cumulative)
constexpr DecoderSymbol(source_type sourceSymbol, Symbol decoderSymbol)
friend std::ostream & operator<<(std::ostream &os, const DecoderSymbol &symbol)
constexpr DecoderSymbol() noexcept
std::ptrdiff_t difference_type
constexpr const value_type * getDecoderSymbolPtr() const noexcept
constexpr state_type getReciprocalFrequency() const noexcept
bool operator==(const PrecomputedSymbol &other) const
constexpr value_type getCumulative() const noexcept
friend std::ostream & operator<<(std::ostream &os, const PrecomputedSymbol &symbol)
constexpr value_type getFrequencyComplement() const noexcept
std::ptrdiff_t difference_type
constexpr PrecomputedSymbol() noexcept
constexpr value_type getReciprocalShift() const noexcept
bool operator!=(const PrecomputedSymbol &other) const
constexpr value_type getFrequency() const noexcept
constexpr PrecomputedSymbol(value_type frequency, value_type cumulative, size_t symbolTablePrecision)
constexpr const value_type * data() const noexcept
constexpr Symbol() noexcept
constexpr value_type getCumulative() const noexcept
constexpr value_type getFrequency() const noexcept
bool operator!=(const Symbol &other) const
friend std::ostream & operator<<(std::ostream &os, const Symbol &symbol)
std::ptrdiff_t difference_type
bool operator==(const Symbol &other) const
std::array< value_type, 2 > mSymbol
constexpr Symbol(value_type frequency, value_type cumulative, size_t symbolTablePrecision=0)
GLuint GLfloat GLfloat GLfloat x1
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
constexpr size_t pow2(size_t n) noexcept
VectorOfTObjectPtrs other