17#ifndef RANS_INTERNAL_CONTAINERS_HASHSYMBOLTABLE_H_
18#define RANS_INTERNAL_CONTAINERS_HASHSYMBOLTABLE_H_
23#include <fairlogger/Logger.h>
33template <
class source_T,
class symbol_T>
53 template <
typename container_T>
78template <
class source_T,
class value_T>
79template <
typename container_T>
82 using namespace utils;
83 using namespace internal;
84 using count_type =
typename value_T::value_type;
87 auto nullElement = [&]() -> value_T {
89 const count_type cumulatedFrequency = renormedHistogram.getNumSamples() - symbolFrequency;
90 return {symbolFrequency, cumulatedFrequency, this->getPrecision()};
95 const auto [trimmedBegin, trimmedEnd] =
trim(renormedHistogram);
97 count_type cumulatedFrequency = 0;
99 renormedHistogram, trimmedBegin, trimmedEnd, [&,
this](
const source_type& sourceSymbol,
const count_type& symbolFrequency) {
100 if (symbolFrequency) {
101 this->mContainer[sourceSymbol] =
symbol_type{symbolFrequency, cumulatedFrequency, this->getPrecision()};
102 cumulatedFrequency += symbolFrequency;
107template <
class source_T,
class value_T>
110 auto iter = this->mContainer.find(sourceSymbol);
111 if (iter == this->mContainer.end()) {
114 return &iter->second;
118template <
typename source_T,
typename symbol_T>
124template <
typename source_T,
typename symbol_T>
127 return std::count_if(symbolTable.
begin(), symbolTable.
end(), [&symbolTable](
const auto&
v) { return !symbolTable.isEscapeSymbol(v.second); });
Abstract container class that defines and implements basic properties shared by histograms and lookup...
Histogram renormed to sum of frequencies being 2^P for use in fast rans coding.
helper functionalities useful for packing operations
value_type getIncompressibleSymbolFrequency() const noexcept
size_t getRenormingBits() const noexcept
bool isEscapeSymbol(source_type sourceSymbol) const noexcept
size_type mSymbolTablePrecision
bool isValidSymbol(const symbol_type &value) const noexcept
const_pointer lookupUnsafe(source_type sourceSymbol) const
size_type getPrecision() const noexcept
typename base_type::source_type source_type
SparseSymbolTable()=default
typename base_type::pointer pointer
typename base_type::value_type symbol_type
typename base_type::const_reference const_reference
bool isEscapeSymbol(const_reference symbol) const noexcept
typename base_type::const_pointer const_pointer
const_reference getEscapeSymbol() const noexcept
typename base_type::difference_type difference_type
size_type size() const noexcept
bool hasEscapeSymbol() const noexcept
typename base_type::container_type container_type
const_pointer lookupSafe(source_type sourceSymbol) const
typename base_type::const_iterator const_iterator
typename base_type::reference reference
typename base_type::size_type size_type
container_type mContainer
const_iterator begin() const noexcept
const_iterator end() const noexcept
typename base_type::value_type value_type
typename base_type::size_type size_type
typename base_type::const_pointer const_pointer
typename base_type::const_reference const_reference
typename base_type::difference_type difference_type
typename base_type::reference reference
typename base_type::container_type container_type
typename base_type::pointer pointer
typename base_type::const_iterator const_iterator
typename base_type::source_type source_type
GLsizei const GLfloat * value
auto getMinMax(const container_T &container, typename container_T::const_iterator begin, typename container_T::const_iterator end, typename container_T::const_reference zeroElem={}) -> std::pair< typename container_T::source_type, typename container_T::source_type >
HistogramView< Hist_IT > trim(const HistogramView< Hist_IT > &buffer)
size_t countNUsedAlphabetSymbols(const AdaptiveHistogram< source_T > &histogram)
std::pair< source_T, source_T > getMinMax(const AdaptiveSymbolTable< source_T, symbol_T > &symbolTable)
Common utility functions.
manipulation of types at compile time