49 for (i=0; i<parTree->
totalSyms && !newChars; i++) {
50 newChars |= parTree->
count[i] > 1;
54 DEBUGCODE(printf(
"fixing %p\n", (
void *)parTree));
58 parTree->
count[i] = 0;
74 DEBUGCODE(printf(
"rescalo %p\n", (
void *)tree));
81 if (tree->
count[i] > 0) {
82 numEscapes -= tree->
count[i];
84 if (tree->
count[i] == 0) {
98 numEscapes = numEscapes >> 1;
99 if (numEscapes == 0) numEscapes = 1;
110 printf(
"count[%d] = %ld %s", origTree->
symbols[j], origTree->
count[j],
113 printf(
"Total: %ld %ld (%p)\n", origTree->
totalCount, origTree->
totalSyms, (
void *)origTree);
120 Uint zLeft = 1, zRight = 0, uSize, uLeft, zNextLeft, j, k, b;
130 if (*zPrevLeft <= *zPrevRight) {
133 *zPrevLeft = child->
left;
135 zRight = child->
left + *zPrevRight - *zPrevLeft + 1;
149 uSize = (*tree)->right + 1;
155 uLeft = sNext->
right + 1;
162 zNextLeft = child->
left;
164 for (k=child->
left+1; j < uSize && k <= child->right && (*(*tree)->text)[uLeft+j] == (*child->
text)[k]; j++, k++);
166 if (k > child->
right) {
170 if ((*zPrevLeft <= *zPrevRight) &&
171 ((*(*prevTree)->text)[*zPrevLeft] == (*child->
text)[k])) {
172 if (k == child->
right) {
177 zRight = k + *zPrevRight - *zPrevLeft;
188 if (k > child->
right) {
207 *zPrevLeft = zNextLeft;
217 if (zLeft <= zRight) {
219 DEBUGCODE(printf(
"New node4: %p\n", (
void *)
new));
223 new->right =
new->left + zRight - zLeft;
226 child->
left = new->right + 1;
242 for (j=0; j <
new->totalSyms; j++) {
243 new->count[j] = (child->
count[j] == 0 ? 0 : 1);
244 new->totalCount +=
new->count[j];
245 new->symbols[j] = child->
symbols[j];
247 new->totalCount *= 2;
253 new->origin = child->
origin;
260 *zPrevLeft =
new->
right + 1;
265 *zPrevRight =
new->
right;
269 if (new->internalFSM) {
271 b = text[i -
new->right - 1];
281 DEBUGCODE(printf(
"New node5: %p\n", (
void *)newLeaf));
282 newLeaf->internal =
False;
283 newLeaf->internalFSM =
False;
284 newLeaf->left = newLeaf->right =
new->right + 1;
285 newLeaf->parent =
new;
290 if (newLeaf->right > 0) {
291 memcpy(*newLeaf->text, *new->text, newLeaf->left);
293 (*newLeaf->text)[newLeaf->left] = b;
298 newLeaf->origin = newLeaf;
301 newLeaf->origin =
new->origin;
313 Uint i, j, k, length, count, numMasked, allCount,
low, *maskedChars, state;
314 Uint zPrevLeft = 1, zPrevRight = 0;
338 DEBUGCODE(printStats(origTree, maskedChars, i));
345 for (j=0; j < origTree->
totalSyms; j++) {
346 allCount += origTree->
count[j];
348 low += origTree->
count[j];
352 if (low > 0 && useSee) {
357 if (count <
See[state][0]) {
405 for(j--; j != -1; j--) {
421 origTree->
count[j]+=2;
433 if (maskedChars[j] != i+1) {
442 if (maskedChars[j] != i+1) {
457 origTree->
count[k] = 1;
470 DEBUGCODE(printStats(origTree, maskedChars, i));
481 DEBUGCODE(printStats(origTree, maskedChars, i));
489 for (j=0; j<length; j++) {
496 origTree->
count[k] = 1;
503 addNodes(text, sym, &tree, &prevTree, i, &zPrevLeft, &zPrevRight);
struct decoderTree ** children
List of pointers to all the children of this node.
Uint totalCount
< Total number of symbols occuring at this state.
Uchar ** text
< Flag that indicates if this node is an internal node of the FSM closure of T(x) ...
Uint textlen
Length of the input text in the encoder.
static void rescale(decoderTree_t tree)
struct decoderTree * tail
Pointer to the node whose label is the tail of this one.
struct decoderTree * parent
Pointer to the parent of this node.
#define True
True boolean constant.
Uint alphasize
Alphabet size.
unsigned char Uchar
Unsigned char type.
Uint right
Index of the rightmost character of the label of this node.
BOOL internalFSM
< Flag that indicates if this node is an internal node of T(x)
struct decoderTree * origin
Pointer to the original node this one descends from.
Uint left
Index of the leftmost character of the label of this node.
Uchar * text
Input text to the encoder.
BOOL isRootDecoderTree(decoderTree_t tree)
Indicates if the parameter node is the root of the tree.
#define FREE(P)
Frees a block of memory and makes the pointer NULL.
static unsigned short int low
#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.
unsigned short int low_count
void verifyDecoder(const decoderTree_t root, decoderTree_t node)
Verify*, only called by the decoder routine.
BOOL used
Flag that indicates if this node has been used to decode eny symbols.
Uint MAX_COUNT
Reset threshold.
Uchar characters[UCHAR_MAX+1]
Characters in text in alphabetical order.
struct decoderTree ** transitions
List of FSM transitions from this state.
#define False
False boolean constant.
Uint alphaindex[UCHAR_MAX+1]
Index of each alphabet character.
decoderTree_t initDecoderTree(BOOL useMalloc)
Creates and initializes a new decoder tree structure instance.
Uint See[1<< 14][2]
SEE table structure.
unsigned short int high_count
void initSee()
Initalizes the SEE table.
Uint * count
Counts of the number of occurrences of each symbol in this state.
static void fixParents(decoderTree_t tree, BOOL *deletedChars)
Remove symbols from the statistics of the ancestors of this node in case that is necessary.
void remove_symbol_from_stream(FILE *stream, SYMBOL *s)
static void addNodes(Uchar *text, Uchar sym, decoderTree_t *tree, decoderTree_t *prevTree, Uint i, Uint *zPrevLeft, Uint *zPrevRight)
void updateSee(Uint state, BOOL escape, Uint alphasize)
Updates the SEE table.
Decoder context tree structure.
short int get_current_count(SYMBOL *s)
int getSeeStateDecoder(decoderTree_t tree, Uint allCount, Uint pos, Uint numMasked, const Uchar *text, Uint alphasize)
Returns the contents of the SEE table for the encoder.
void decode(decoderTree_t tree, const Uint textlen, FILE *compressedFile, FILE *output, const BOOL useSee)
Decodes the compressed file data to the output file (for non-binary alphabet).