Arithmetic coding tutorial code  1
AC
Data Structures | Typedefs | Functions | Variables
AC Namespace Reference

Data Structures

class  Base
 
class  Decoder
 
class  Encoder
 

Typedefs

typedef std::function< void(int, int, F_t, F_t, double)> printit_t
 
typedef uint32_t I_t
 types for variables defining intervals More...
 
typedef uint64_t long_I_t
 
typedef I_t F_t
 types for variables defining frequencies More...
 
typedef std::pair< I_t, I_tinterval_t
 struct to represent an interval More...
 
typedef std::function< void(int, void *)> output_callback_t
 type for callbacks More...
 
typedef std::function< int(void *)> input_callback_t
 type for bit reader call More...
 

Functions

std::string string_hex (I_t b)
 prints an integer in a string More...
 
std::string string_binary_comma (I_t b, std::string sep="'")
 
void freq2cum_freq (F_t cum_freq[], F_t freq[], int max_symb, int assert_non_zero=1)
 computes the cumulative cum_freq given the frequencies of symbols More...
 
void prob2cum_freq (F_t cum_freq[], double prob[], int max_symb)
 computes the cum_freq given the probabilities More...
 
int renormalize_frequencies (AC::F_t *fr, int n_symbols, unsigned int max_freq=AC::MAX_FREQ)
 
double compute_entropy (F_t *freq, int MAX_SYMB)
 compute the entropy given the frequencies More...
 
void print_table_generic (std::function< void(int)> head, printit_t printit, F_t *fr, F_t *cufr, int n_symbols, const int columns=6)
 
void print_table_freq (F_t *fr, F_t *cufr, int n_symbols, const int columns=6, FILE *out=stderr)
 prints the table of frequencies More...
 
void print_table_freq_ascii (F_t *fr, F_t *cufr, int n_symbols, const int columns=6, FILE *out=stderr)
 prints the table of frequencies, with ascii characters More...
 
void print_table_cum_freq_ascii (F_t *fr, F_t *cufr, int n_symbols, FILE *out=stdout, int columns=4)
 prints the table of frequencies and cumulative frequencies, with ascii symbols More...
 
void print_table_cum_freq (F_t *fr, F_t *cufr, int n_symbols, FILE *out=stdout, const int columns=4)
 prints the table of frequencies and cumulative frequencies More...
 

Variables

const char * bit_rep [16]
 
const char * hex_rep [16]
 
const int NO_SYMBOL = -1
 value that represents a non symbol More...
 
const int FLUSH_SYMBOL = -2
 
const int MIN_SYMBOL = 0
 
const I_t MAX_FREQ = ((I_t)1) << (AC_representation_bitsize-2)
 the sum of all frequencies of symbols cannot exceed this value More...
 

Typedef Documentation

◆ F_t

typedef I_t AC::F_t

types for variables defining frequencies

◆ I_t

typedef uint32_t AC::I_t

types for variables defining intervals

◆ input_callback_t

typedef std::function<int(void *)> AC::input_callback_t

type for bit reader call

◆ interval_t

typedef std::pair<I_t, I_t> AC::interval_t

struct to represent an interval

◆ long_I_t

typedef uint64_t AC::long_I_t

◆ output_callback_t

typedef std::function<void(int,void *)> AC::output_callback_t

type for callbacks

◆ printit_t

typedef std::function<void(int,int,F_t,F_t,double)> AC::printit_t

Function Documentation

◆ compute_entropy()

double AC::compute_entropy ( F_t freq,
int  MAX_SYMB 
)

compute the entropy given the frequencies

◆ freq2cum_freq()

void AC::freq2cum_freq ( F_t  cum_freq[],
F_t  freq[],
int  max_symb,
int  assert_non_zero = 1 
)

computes the cumulative cum_freq given the frequencies of symbols

◆ print_table_cum_freq()

void AC::print_table_cum_freq ( F_t fr,
F_t cufr,
int  n_symbols,
FILE *  out = stdout,
const int  columns = 4 
)

prints the table of frequencies and cumulative frequencies

◆ print_table_cum_freq_ascii()

void AC::print_table_cum_freq_ascii ( F_t fr,
F_t cufr,
int  n_symbols,
FILE *  out = stdout,
int  columns = 4 
)

prints the table of frequencies and cumulative frequencies, with ascii symbols

◆ print_table_freq()

void AC::print_table_freq ( F_t fr,
F_t cufr,
int  n_symbols,
const int  columns = 6,
FILE *  out = stderr 
)

prints the table of frequencies

◆ print_table_freq_ascii()

void AC::print_table_freq_ascii ( F_t fr,
F_t cufr,
int  n_symbols,
const int  columns = 6,
FILE *  out = stderr 
)

prints the table of frequencies, with ascii characters

◆ print_table_generic()

void AC::print_table_generic ( std::function< void(int)>  head,
printit_t  printit,
F_t fr,
F_t cufr,
int  n_symbols,
const int  columns = 6 
)
Parameters
headprints the heading of a columns
printitprints the content of columns

◆ prob2cum_freq()

void AC::prob2cum_freq ( F_t  cum_freq[],
double  prob[],
int  max_symb 
)

computes the cum_freq given the probabilities

◆ renormalize_frequencies()

int AC::renormalize_frequencies ( AC::F_t fr,
int  n_symbols,
unsigned int  max_freq = AC::MAX_FREQ 
)

reduces the frequencies if they are too high returns positive number if the frequencies were renormalized

Parameters
frtable of frequencies
n_symbolsnumber of symbols
max_freqmaximum frequency

◆ string_binary_comma()

std::string AC::string_binary_comma ( I_t  b,
std::string  sep = "'" 
)

prints a string in binary, as if it was a decimal number; used to print the extreme of an interval

◆ string_hex()

std::string AC::string_hex ( I_t  b)

prints an integer in a string

Variable Documentation

◆ bit_rep

const char* AC::bit_rep[16]
Initial value:
= {
[ 0] = "0000", [ 1] = "0001", [ 2] = "0010", [ 3] = "0011",
[ 4] = "0100", [ 5] = "0101", [ 6] = "0110", [ 7] = "0111",
[ 8] = "1000", [ 9] = "1001", [10] = "1010", [11] = "1011",
[12] = "1100", [13] = "1101", [14] = "1110", [15] = "1111",
}

◆ FLUSH_SYMBOL

const int AC::FLUSH_SYMBOL = -2

value that represents a succeful deflushing (note that this symbol is not counted in the internal count of symbols)

◆ hex_rep

const char* AC::hex_rep[16]
Initial value:
= {
[ 0] = "0", [ 1] = "1", [ 2] = "2", [ 3] = "3",
[ 4] = "4", [ 5] = "5", [ 6] = "6", [ 7] = "7",
[ 8] = "8", [ 9] = "9", [10] = "A", [11] = "B",
[12] = "C", [13] = "D", [14] = "E", [15] = "F",
}

◆ MAX_FREQ

const I_t AC::MAX_FREQ = ((I_t)1) << (AC_representation_bitsize-2)

the sum of all frequencies of symbols cannot exceed this value

◆ MIN_SYMBOL

const int AC::MIN_SYMBOL = 0

minimum value for a symbol, 0 is the common choice for computer programs, 1 is the common choice for people

◆ NO_SYMBOL

const int AC::NO_SYMBOL = -1

value that represents a non symbol