40 printf(
"count[%d] = %ld %s", origTree->
symbols[j], origTree->
count[j],
43 printf(
"Total: %ld %ld (%p)\n", origTree->
totalCount, origTree->
totalSyms, (
void *)origTree);
64 for (i=0; i<parTree->
totalSyms && !newChars; i++) {
65 newChars |= parTree->
count[i] > 1;
69 DEBUGCODE(printf(
"fixing %p\n", (
void *)parTree));
73 parTree->
count[i] = 0;
89 DEBUGCODE(printf(
"rescalo %p\n", (
void *)tree));
96 if (tree->
count[i] > 0) {
97 numEscapes -= tree->
count[i];
99 if (tree->
count[i] == 0) {
113 numEscapes = numEscapes >> 1;
114 if (numEscapes == 0) numEscapes = 1;
128 Uint i, j, k, numMasked,
low,
pos, allCount, noMask, *maskedChars, state;
146 assert(origTree != NULL);
151 DEBUGCODE(printStats(origTree, maskedChars, i));
156 low = j = allCount = 0;
158 allCount += origTree->
count[j];
160 found = (origTree->
symbols[j] == sym) && (origTree->
count[j] > 0);
161 if (origTree->
symbols[j] == sym && origTree->
count[j] == 0) {
166 low += origTree->
count[j];
170 while (!found && ++j < origTree->
totalSyms);
176 for (k=j+1; k < origTree->
totalSyms; k++) {
177 allCount += origTree->
count[k];
179 low += origTree->
count[k];
184 if (low > 0 && useSee) {
206 origTree->
count[j] += 2;
213 if (origTree->
totalCount > 0 && low > 0 && useSee) {
221 assert(
See[state][1] > 0);
237 for (j--; j != -1; j--) {
248 origTree->
count[noMask] = 1;
262 for (j=0, allCount=0, low=0; j<
alphasize; j++) {
263 if (maskedChars[j] != i+1) {
286 DEBUGCODE(printStats(origTree, maskedChars, i));
299 DEBUGCODE(printStats(origTree, maskedChars, i));
void addSymbol(fsmTree_t tree, const Uchar sym)
Adds a new symbol to this tree node.
void encode(fsmTree_t tree, FILE *compressedFile, const Uchar *text, const Uint textlen, const BOOL useSee)
Encode the input data into the output file using the tree as model.
Uint textlen
Length of the input text in the encoder.
void encode_symbol(FILE *stream, SYMBOL *s)
struct fsmTree ** transitions
List of FSM transitions from this state.
BOOL isRootFsmTree(const fsmTree_t tree)
Indicates if the parameter node is the root of the tree.
#define True
True boolean constant.
Uint alphasize
Alphabet size.
unsigned char Uchar
Unsigned char type.
static void fixParents(fsmTree_t tree, BOOL *deletedChars)
Remove symbols from the statistics of the ancestors of this node in case that is necessary.
Uchar * text
Input text to the encoder.
BOOL used
Flag that indicates if this node has been used to encode a symbol.
#define FREE(P)
Frees a block of memory and makes the pointer NULL.
static unsigned short int low
struct fsmTree * origin
Pointer to the original node this one descends from.
#define CALLOC(S, T, N)
Allocs a new block of memory and sets all its bits to zero.
unsigned long Uint
Unsigned int type.
#define BOOL
Boolean data type.
Uint * count
List containing the number of occurrences of each character in this state.
unsigned short int low_count
Encoder context tree structure.
static short pos
Current position in the buffer.
Uint MAX_COUNT
Reset threshold.
#define False
False boolean constant.
int getSeeStateEncoder(fsmTree_t tree, Uint allCount, Uint pos, Uint numMasked, const Uchar *text, Uint alphasize)
Returns the contents of the SEE table for the encoder.
Uint totalSyms
Total number of symbols occuring at this state.
Uint alphaindex[UCHAR_MAX+1]
Index of each alphabet character.
Uint See[1<< 14][2]
SEE table structure.
unsigned short int high_count
void initSee()
Initalizes the SEE table.
#define GETINDEX(N)
Returns the index of the Nth character in the input text.
struct fsmTree * parent
Pointer to the parent of this node.
void updateSee(Uint state, BOOL escape, Uint alphasize)
Updates the SEE table.
static void rescale(fsmTree_t tree)