#include <context.h>
Inheritance diagram for Context:
Public Methods | |
Context (void) | |
A constructor. More... | |
Context (int, ContextType) | |
A constructor. Sets the size and type directly. More... | |
virtual | ~Context (void) |
A destructor. More... | |
virtual void | setType (int, ContextType) |
Initialization of the context with given size and type. More... | |
virtual int | initialize (void) |
Initialize the context. More... | |
virtual int | lastFixedSymbol (void) |
Return the value of last fixed symbol in the context. | |
virtual int | encode (int) throw (ExaltContextNotInitializedException, ExaltIOException) |
Encode symbol using given arithmetic codec. More... | |
virtual int | encodeEndOfMessage () throw (ExaltContextNotInitializedException, ExaltIOException) |
Encode the "end of message" symbol. | |
virtual int | decode (void) throw (ExaltContextNotInitializedException, ExaltIOException) |
Decode symbol using given arithmetic codec. More... | |
virtual void | purgeContext (void) |
Purge the contents of the context. More... | |
virtual int | installSymbol (int) |
Install new symbol. More... | |
Protected Methods | |
virtual void | getInterval (FreqValue *, FreqValue *, int) |
Get interval for given symbol. More... | |
virtual void | halveContext (void) |
Halve frequencies in the context. More... | |
virtual void | initZeroFreq () |
Initialize number of singletons. More... | |
Protected Attributes | |
int | initialSize |
Original size of context. | |
int | maxLength |
Length of the tree and current length. | |
int | length |
Length of the tree and current length. | |
FreqValue | nSingletons |
Number of symbols with frequency = 1. | |
ContextType | type |
Type of the context. | |
int | nSymbols |
Count of installed symbols. | |
FreqValue | total |
Total sum of all frequencies. | |
FreqValue * | tree |
Fenwick's binary index tree. | |
FreqValue | incr |
Current increment. | |
int | mostFreqSymbol |
Symbol with highest frequency. | |
FreqValue | mostFreqCount |
The highest frequency. | |
FreqValue | mostFreqPos |
Position of the most frequent symbol. |
Class represents a frequency table using a Fenwick's binary index tree. Table may be static or dynamic. Dynamic tables may grow above their intial length as new symbols are installed.
Definition at line 109 of file context.h.
|
A constructor. Calls construcotr of class ContextBase. Definition at line 164 of file context.cpp. References tree. |
|
A constructor. Sets the size and type directly. Calls initContext().
Definition at line 178 of file context.cpp. References ContextType, setType, tree, and type. |
|
A destructor. Frees the memory occupied by Fenwick's tree. Definition at line 190 of file context.cpp. References tree. |
|
Decode symbol using given arithmetic codec. Decode symbol based on current context.
Implements ContextBase. Definition at line 489 of file context.cpp. References ADJUST_ZERO_FREQ, DynamicContext, FreqValue, GET_COUNT, INCR_SYMBOL_PROB, MAX_FREQUENCY, and ContextBase::NotKnown. Referenced by XmlCodec::decode. |
|
Encode symbol using given arithmetic codec. Encode a symbol given its context. The lower and upper bounds are determined using the frequency table, and then passed on to the coder. If the symbol has zero frequency, code an escape symbol and return Context::NotKnown, otherwise return Context::Ok.
Implements ContextBase. Definition at line 389 of file context.cpp. References ADJUST_ZERO_FREQ, DynamicContext, FATAL, FreqValue, INCR_SYMBOL_PROB, MAX_FREQUENCY, ContextBase::NotKnown, ContextBase::Ok, and ZERO_FREQ_PROB. |
|
Get interval for given symbol. Get the low and high limits of the frequency interval occupied by a symbol.
Definition at line 620 of file context.cpp. References FORW, FreqValue, GET_COUNT, maxLength, and tree. Referenced by halveContext, and installSymbol. |
|
Halve frequencies in the context. This method is responsible for halving all the frequency counts in a context. It halves context in linear time by converting tree to list of freqs and then back again. It ensures the most probable symbol size and range stay updated. If halving the context gives rise to a sudden drop in the ZERO_FREQ_PROB(), and if it was the most probable symbol, it will stay recorded as the most probable symbol even if it isn't. This may cause slight compression inefficiency. (The ZERO_FREQ_PROB() as implemented does not have this characteristic, and in this case the inefficiency cannot occur.) Definition at line 649 of file context.cpp. References ADJUST_ZERO_FREQ, FreqValue, getInterval, incr, maxLength, MIN_INCR, mostFreqCount, mostFreqPos, mostFreqSymbol, nSingletons, StaticContext, total, tree, type, and ZERO_FREQ_PROB. Referenced by installSymbol. |
|
Initialize the context. Install all symbols of the initial context.
Implements ContextBase. Definition at line 274 of file context.cpp. References ContextBase::endOfMessage, FATAL, ContextBase::initialized, installSymbol, and ContextBase::TooManySymbols. Referenced by XmlCodec::decode. |
|
Initialize number of singletons. If context is dynamic, nSingletons will be equal to incr` otherwise it will be 0. Definition at line 201 of file context.cpp. References DynamicContext, incr, nSingletons, and type. Referenced by purgeContext, and setType. |
|
Install new symbol. Install a new symbol in a context's frequency table.
Implements ContextBase. Definition at line 307 of file context.cpp. References ADJUST_ZERO_FREQ, DynamicContext, ERR, FreqValue, getInterval, halveContext, incr, INCR_SYMBOL_PROB, length, MAX_FREQUENCY, maxLength, ContextBase::NoMemory, nSingletons, nSymbols, ContextBase::Ok, ContextBase::TooManySymbols, total, tree, and type. Referenced by initialize. |
|
Purge the contents of the context. Frees memory allocated for a context and initialize empty context of original size. Implements ContextBase. Definition at line 722 of file context.cpp. References ADJUST_ZERO_FREQ, F_BITS, FATAL, FreqValue, incr, initialSize, initZeroFreq, length, maxLength, mostFreqCount, mostFreqPos, mostFreqSymbol, nSingletons, nSymbols, total, and tree. |
|
Initialization of the context with given size and type. Create a new frequency table using a binary index tree. Table may be static or dynamic depending on the type parameter. Dynamic tables may grow above their initial length as new symbols are installed. Maximum length (maxLength) is set to 2^ceil(log_2 length). Valid tree indices are 1..maxLength - 1 (maxLength refers to the maximum length of the structure before it needs to expand).
Implements ContextBase. Definition at line 221 of file context.cpp. References ADJUST_ZERO_FREQ, ContextType, ContextBase::endOfMessage, F_BITS, FATAL, FreqValue, incr, initialSize, initZeroFreq, length, maxLength, mostFreqCount, mostFreqPos, mostFreqSymbol, nSingletons, nSymbols, total, tree, and type. Referenced by Context, and XmlCodec::decode. |