14#include <string/LinearString.h>
18namespace compression {
20template <
class SymbolType,
class Model >
24 unsigned long long m_value = 0;
25 unsigned long long m_low = 0;
26 unsigned long long m_high = 0;
28 unsigned long long m_range = 0;
29 unsigned m_prob_count = 0;
30 unsigned m_scaled_value = 0;
32 static const unsigned valid_bits =
sizeof (
unsigned long long ) * 8 / 2;
33 static const unsigned long long max_code = ~0ull >> valid_bits;
34 static const unsigned long long one_half = ( max_code >> 1 ) + 1;
35 static const unsigned long long one_fourth = ( max_code >> 2 ) + 1;
36 static const unsigned long long three_fourths = one_half + one_fourth;
38 template <
class Callback >
39 void fillVariables ( Callback &&
callback ) {
41 if ( m_high < one_half || m_low >= one_half ) {
43 }
else if ( m_low >= one_fourth && m_high < three_fourths ) {
44 m_value -= one_fourth;
61 m_range = m_high - m_low + 1;
62 m_prob_count = m_model.getCount ( );
63 m_scaled_value = ( ( m_value - m_low + 1 ) * m_prob_count - 1 ) / m_range;
67 template <
class Callback >
69 fillVariables ( std::forward < Callback && > (
callback ) );
73 return m_model.isEof ( m_scaled_value );
76 template <
class Callback >
80 SymbolType c = m_model.getChar ( m_scaled_value, prob_low, prob_high );
83 m_high = m_low + m_range * prob_high / m_prob_count - 1;
84 m_low = m_low + m_range * prob_low / m_prob_count;
86 fillVariables ( std::forward < Callback && > (
callback ) );
98 template <
class SymbolType >
101 auto input = [ & ] ( ) {
102 return index >= source.size ( ) ? 0 : source [ index ++ ] ? 1 : 0;
108 while ( ! decoder.
isEof ( ) ) {
Definition: ArithmeticModel.h:13
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
Linear string.
Definition: LinearString.h:57
Definition: ArithmeticDecompression.h:96
static string::LinearString< SymbolType > decompress(const ext::vector< bool > &source, const ext::set< SymbolType > &alphabet)
Definition: ArithmeticDecompression.h:99
Definition: ArithmeticDecompression.h:21
SymbolType decode(Callback &&callback)
Definition: ArithmeticDecompression.h:77
ArithmeticDecoder(Model model, Callback &&callback)
Definition: ArithmeticDecompression.h:68
Model & getModel()
Definition: ArithmeticDecompression.h:91
bool isEof()
Definition: ArithmeticDecompression.h:72
Definition: BarSymbol.cpp:12
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
for(const StateType &state :fsm.getStates()) renamingData.insert(std Rename::RenamedAutomaton< T > result(renamingData.at(fsm.getInitialState()))
Definition: Rename.h:253
int callback(struct dl_phdr_info *info, size_t, void *data)
Definition: simpleStacktrace.cpp:25
Definition: FordFulkerson.hpp:16
Definition: ArithmeticCompression.h:18