Context algorithm
Semi-predictive context algorithm implementation
 All Data Structures Files Functions Variables Typedefs Macros Pages
decoderTree.c
Go to the documentation of this file.
1 /* Copyright 2013 Jorge Merlino
2 
3  This file is part of Context.
4 
5  Context is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Context is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Context. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include <assert.h>
20 #include "spacedef.h"
21 #include "debug.h"
22 #include "decoderTree.h"
23 #include "alpha.h"
24 #include "arithmetic/coder.h"
25 #include "arithmetic/bitio.h"
26 #ifndef WIN32
27 #include <obstack.h>
28 #endif
29 
31 #define ROOT -1
32 
33 #define obstack_chunk_alloc malloc
34 #define obstack_chunk_free free
35 
38 
41 
42 #ifndef WIN32
43 static struct obstack nodeStack;
44 #endif
45 
60 static void fastCanonize(decoderTree_t tree, Uint xLeft, Uint xRight, decoderTree_t node, decoderTree_t *r, Uint *uLeft, Uint *uRight, Uint *vLeft, Uint *vRight) {
61  BOOL end;
62  decoderTree_t child = NULL;
63 
64  *vLeft = 1;
65  *vRight = 0; /* v is empty */
66 
67  if (tree->left != ROOT) {
68  xLeft += tree->right + 1;
69  }
70  end = xLeft > xRight;
71 
72  while (!end) {
73  child = tree->children[GETINDEX2(xLeft)];
74  if ((child->right - child->left) <= (xRight - xLeft)) {
75  xLeft += child->right - child->left + 1;
76  tree = child;
77  end = xLeft > xRight;
78  }
79  else {
80  end = True;
81  }
82  }
83 
84  *r = tree;
85  if (xLeft <= xRight) {
86  *uLeft = xLeft;
87  *uRight = xRight;
88  }
89  else {
90  *uLeft = 1;
91  *uRight = 0; /* u is empty */
92  }
93 }
94 
109 static void canonize(decoderTree_t tree, Uint xLeft, Uint xRight, decoderTree_t node, decoderTree_t *r, Uint *uLeft, Uint *uRight, Uint *vLeft, Uint *vRight) {
110  decoderTree_t child;
111  BOOL end = False;
112  Uint i, xLeftStart;
113 
114  if (xLeft > xRight) {
115  *uLeft = 1;
116  *uRight = 0; /* u is empty */
117  end = True;
118  }
119  else if (tree->left != ROOT) {
120  xLeft += tree->right + 1;
121  }
122 
123  while (!end) {
124  child = tree->children[GETINDEX2(xLeft)];
125  if (child) { /* there is an edge in the direction of xLeft */
126  xLeftStart = xLeft;
127  for (i=child->left; (i<=child->right) && (xLeft<=xRight) && ((*child->text)[i] == (*node->text)[xLeft]); i++, xLeft++);
128  if (i > child->right) { /* all the edge is in x */
129  tree = child;
130  if (xLeft > xRight) {
131  end = True;
132  *uLeft = 1;
133  *uRight = 0; /* u is empty */
134  }
135  }
136  else {
137  end = True;
138  *uLeft = xLeftStart;
139  *uRight = xLeft-1;
140  }
141  }
142  else {
143  end = True;
144  *uLeft = 1;
145  *uRight = 0; /* u is empty */
146  }
147  }
148 
149  *r = tree;
150  *vLeft = xLeft;
151  *vRight = xRight;
152 }
153 
154 
166 static decoderTree_t insert (decoderTree_t r, decoderTree_t node, Uint uLeft, Uint uRight, Uint vLeft, Uint vRight, BOOL decoder) {
167  decoderTree_t new = initDecoderTree(False), newLeaf, ret, child;
168  BOOL leaf;
169  Uint i,j, cidx = GETINDEX2(0);
170 
171  DEBUGCODE(printf("New node1: %p\n", (void *)new));
172  if (uLeft > uRight) {
173  for (i=0; i<alphasize && !r->children[i]; i++);
174  leaf = i == alphasize;
175 
176  if (r->internal && vRight > vLeft) { /* if a non atomical node is added we have to insert the leaf of T(x) which is the parent of this node */
177  newLeaf = initDecoderTree(False);
178  DEBUGCODE(printf("New node3: %p\n", (void *)newLeaf));
179  newLeaf->left = newLeaf->right = (r->right != ROOT ? r->right + 1 : 0);
180  newLeaf->internal = False;
181  newLeaf->internalFSM = !decoder;
182 
183  if (leaf && (r->left != ROOT)) {
184  newLeaf->text = r->text;
185  REALLOC(*newLeaf->text, *newLeaf->text, Uchar, newLeaf->right + 1);
186  }
187  else {
188  MALLOC(newLeaf->text, Uchar *, 1);
189  CALLOC(*newLeaf->text,Uchar, newLeaf->right + 1);
190  if (newLeaf->left > 0) {
191  memcpy(*newLeaf->text, *r->text, newLeaf->left);
192  }
193  }
194  (*newLeaf->text)[newLeaf->left] = (*node->text)[vLeft];
195  r->children[GETINDEX2(vLeft)] = newLeaf;
196  newLeaf->parent = r;
197  newLeaf->origin = newLeaf;
198 
199  if (decoder) {
200  for (i=0; i<alphasize; i++) {
201  if (i != cidx) {
202  newLeaf->transitions[i] = r->transitions[i];
203  }
204  }
205  }
206  vLeft++;
207  leaf = True;
208  r = newLeaf;
209  }
210 
211  new->left = (r->right != ROOT ? r->right + 1 : 0);
212  new->right = new->left + vRight - vLeft;
213  new->internal = False;
214  new->internalFSM = !decoder;
215 
216  if (leaf && (r->left != ROOT)) {
217  new->text = r->text;
218  REALLOC(*new->text, *new->text, Uchar, new->right + 1);
219  }
220  else {
221  MALLOC(new->text, Uchar *, 1);
222  CALLOC(*new->text,Uchar, new->right + 1);
223  /*printf("left: %d, right: %d isRoot: %d\n", new->left, new->right, isRootDecoderTree(r));*/
224  if (new->left > 0) {
225  memcpy(*new->text, *r->text, new->left); /* new->left = r->right + 1 */
226  }
227  }
228  for (i=vLeft, j=new->left; i<=vRight; i++, j++) {
229  (*new->text)[j] = (*node->text)[i];
230  }
231  r->children[GETINDEX2(vLeft)] = new;
232  new->parent = r;
233 
234  if (r->internal) {
235  new->origin = new;
236  }
237  else {
238  new->origin = r->origin;
239  }
240 
241  if (decoder) {
242  for (i=0; i<alphasize; i++) {
243  if (i != cidx) {
244  new->transitions[i] = r->transitions[i];
245  }
246  }
247  }
248 
249  ret = new;
250  }
251  else {
252  /* split */
253  new->left = (r->right != ROOT ? r->right + 1 : 0);
254  new->right = new->left + uRight - uLeft;
255 
256  child = r->children[GETINDEX2(uLeft)];
257  new->internal = child->internal;
258  new->internalFSM = !decoder || child->internalFSM;
259 
260  new->children[alphaindex[(*child->text)[new->right+1]]] = child;
261  child->left = new->right + 1;
262  child->parent = new;
263  new->text = child->text;
264 
265  new->parent = r;
266  r->children[GETINDEX2(uLeft)] = new;
267 
268  if (r->internal) {
269  new->origin = new;
270  }
271  else {
272  new->origin = child->origin;
273  }
274 
275  if (decoder) {
276  new->totalSyms = child->totalSyms;
277  new->totalCount = 0;
278  for (i=0; i<alphasize; i++) {
279  if (i != cidx) {
280  new->transitions[i] = r->transitions[i];
281  }
282 
283  if (i < new->totalSyms) {
284  new->count[i] = (child->count[i] == 0 ? 0 : 1);
285  new->totalCount += new->count[i];
286  new->symbols[i] = child->symbols[i];
287  }
288  }
289  new->totalCount *= 2; /* symbols and escapes */
290  }
291 
292  new->traversed[alphaindex[(*new->text)[new->right+1]]] = r->traversed[GETINDEX2(uLeft)];
293 
294  if (vLeft <= vRight) {
295  if (new->internal && vRight > vLeft) { /* if a non atomical node is added we have to insert the leaf of T(x) which is the parent of this node */
296  newLeaf = initDecoderTree(False);
297  DEBUGCODE(printf("New node6: %p\n", (void *)newLeaf));
298  newLeaf->left = newLeaf->right = (new->right != ROOT ? new->right + 1 : 0);
299  newLeaf->internal = False;
300  newLeaf->internalFSM = !decoder;
301 
302  MALLOC(newLeaf->text, Uchar *, 1);
303  CALLOC(*newLeaf->text,Uchar, newLeaf->right + 1);
304  if (newLeaf->left > 0) {
305  memcpy(*newLeaf->text, *new->text, newLeaf->left);
306  }
307 
308  (*newLeaf->text)[newLeaf->left] = (*node->text)[vLeft];
309  new->children[GETINDEX2(vLeft)] = newLeaf;
310  newLeaf->parent = new;
311  newLeaf->origin = newLeaf;
312 
313  if (decoder) {
314  for (i=0; i<alphasize; i++) {
315  if (i != cidx) {
316  newLeaf->transitions[i] = r->transitions[i];
317  }
318  }
319  }
320  vLeft++;
321  new = newLeaf;
322  }
323 
324  newLeaf = initDecoderTree(False);
325  DEBUGCODE(printf("New node2: %p\n", (void *)newLeaf));
326  /* add */
327  newLeaf->internal = False;
328  newLeaf->internalFSM = !decoder;
329  newLeaf->left = new->right + 1;
330  newLeaf->right = newLeaf->left + vRight - vLeft;
331  newLeaf->parent = new;
332  new->children[GETINDEX2(vLeft)] = newLeaf;
333 
334  MALLOC(newLeaf->text, Uchar *, 1);
335  CALLOC(*newLeaf->text,Uchar, newLeaf->right + 1);
336  memcpy(*newLeaf->text, *new->text, newLeaf->left);
337  for (i=vLeft, j=newLeaf->left; i<=vRight; i++, j++) {
338  (*newLeaf->text)[j] = (*node->text)[i];
339  }
340 
341  if (new->internal) {
342  newLeaf->origin = newLeaf;
343  }
344  else {
345  newLeaf->origin = new->origin;
346  }
347 
348  if (decoder) {
349  for (i=0; i<alphasize; i++) {
350  if (i != cidx) {
351  newLeaf->transitions[i] = new->transitions[i];
352  }
353  }
354  }
355 
356  ret = newLeaf;
357  }
358  else {
359  ret = new;
360  }
361  }
362 
363  return ret;
364 }
365 
366 
374 static void verify(const decoderTree_t root, decoderTree_t node, BOOL fast, BOOL decoder) {
375  Uint xLeft, uLeft, uRight, vLeft, vRight, i, cidx;
376  decoderTree_t r, x;
377 
378  if (node->left != ROOT) {
379  cidx = GETINDEX2(0);
380  xLeft = 1;
381 
382  if (fast) {
383  fastCanonize(root, xLeft, node->right, node, &r, &uLeft, &uRight, &vLeft, &vRight);
384  }
385  else {
386  canonize(root, xLeft, node->right, node, &r, &uLeft, &uRight, &vLeft, &vRight);
387  }
388 
389  if ((uLeft <= uRight) || (vLeft <= vRight)) {
390  x = insert(r, node, uLeft, uRight, vLeft, vRight, decoder);
391  if (uLeft <= uRight) {
392  if (r->traversed[GETINDEX2(uLeft)]) {
393  verify((r->left == ROOT ? r : r->tail), r->children[GETINDEX2(uLeft)], True, decoder);
394  }
395  }
396  else if (r->traversed[GETINDEX2(vLeft)]) {
397  verify((r->left == ROOT ? r : r->tail), r->children[GETINDEX2(vLeft)], False, decoder);
398  }
399  }
400  else { /* the node already exists */
401  x = r;
402  }
403  node->tail = x;
404 
405  x->transitions[cidx] = node;
406  }
407 
408  for (i=0; i<alphasize; i++) {
409  if (!node->traversed[i]) {
410  node->traversed[i] = True;
411  if (node->children[i]) {
412  verify((node->left == ROOT ? node : node->tail), node->children[i], False, decoder);
413  }
414  }
415  }
416 }
417 
418 void verifyDecoder(const decoderTree_t root, decoderTree_t node) {
419  verify(root, node, False, True);
420 }
421 
427 static void propagateTransitions(decoderTree_t *transitions, decoderTree_t tree) {
428  Uint i;
429 
430  for (i=0; i<alphasize; i++) {
431  if (!tree->transitions[i]) {
432  tree->transitions[i] = transitions[i];
433  }
434  }
435 
436  for (i=0; i<alphasize; i++) {
437  if (tree->children[i]) {
438  propagateTransitions(tree->transitions, tree->children[i]);
439  }
440  }
441 }
442 
448 static BOOL readEncoder(FILE *file) {
449  SYMBOL s;
450  Uint count, totalN = totalNodes, internalN = internalNodes, shift = 0;
451  BOOL internal;
452 
453  if (totalNodes == internalNodes) {
454  return True;
455  }
456  else if (internalNodes == 0) {
457  return False;
458  }
459  else {
460  while ((totalN & 0xFFFFC000) != 0) { /* some of the most significative 18 bits on */
461  totalN >>= 1;
462  shift++;
463  }
464 
465  if (shift > 0) {
466  internalN >>= shift;
467  totalN = (internalN * alphasize) + 1;
468  }
469 
470  s.scale = totalN;
471  count = get_current_count(&s);
472  internal = count < internalN;
473 
474  if (internal) {
475  s.low_count = 0;
476  s.high_count = internalN;
477  internalNodes--;
478  }
479  else {
480  s.low_count = internalN;
481  s.high_count = totalN;
482  }
483  totalNodes--;
484  remove_symbol_from_stream(file, &s);
485 
486  return internal;
487  }
488 }
489 
490 
496 static int readDecoderTreeRec (decoderTree_t t, FILE *file) {
497  Uint i;
498  int onlyChild = -1 /* no children */, childStatus;
499  decoderTree_t child;
500  BOOL internal;
501 
502  for (i=0; i<alphasize; i++) {
503  internal = readEncoder(file);
504  if (internal) {
505  if (onlyChild == -1) {
506  onlyChild = i; /* one child */
507  }
508  else if (onlyChild >= 0) {
509  onlyChild = -2; /* more than one children */
510  }
511 
512  t->children[i] = initDecoderTree(True);
513  child = t->children[i];
514  child->parent = t;
515  child->internal = True;
516  child->internalFSM = True;
517  if (t->left == ROOT) {
518  child->left = child->right = 0;
519  MALLOC(child->text, Uchar *, 1);
520  CALLOC(*child->text, Uchar, 1);
521  (*child->text)[0] = characters[i];
522  }
523  else {
524  child->left = child->right = t->left + 1;
525  if (onlyChild >= 0) { /* first child */
526  child->text = t->text;
527  REALLOC(*child->text, *child->text, Uchar, child->left + 1);
528  }
529  else {
530  MALLOC(child->text, Uchar *, 1);
531  CALLOC(*child->text, Uchar, child->left + 1);
532  memcpy(*child->text, *t->text, child->left);
533  }
534  (*child->text)[child->left] = characters[i];
535  }
536  childStatus = readDecoderTreeRec(child, file);
537  if (childStatus >= 0) { /* this child has outgoing degree = 1 */
538  child->children[childStatus]->left = child->left;
539  t->children[i] = child->children[childStatus];
540  t->children[i]->parent = t;
541  freeDecoderTree(child, child->children[childStatus]->text != child->text);
542  }
543  }
544  }
545  return onlyChild;
546 }
547 
548 #ifdef DEBUG
549 
555 static void printRec(const decoderTree_t tree, int level) {
556  int i;
557 
558  if (level > 0) {
559  for (i=1; i<=level; i++) {
560  printf("-");
561  }
562 
563  printf("%ld - %ld (%p) parent: %p orig: %p\n", tree->left, tree->right, (void*)tree, (void*)tree->parent, (void*)tree->origin);
564  for (i=0; i<tree->right; i++) {
565  printf("%d-", *(*(tree->text) + i));
566  }
567  printf("%d\n", *(*(tree->text) + tree->right));
568  }
569  else {
570  printf("(root)\n");
571  }
572 
573  level++;
574  for (i=0; i<alphasize; i++) {
575  if (tree->children[i]) {
576  printf ("hijo %d ", i);
577  printRec(tree->children[i], level);
578  }
579  }
580 }
581 
582 #endif
583 
585 #ifndef WIN32
586  obstack_init (&nodeStack);
587  if (obstack_chunk_size (&nodeStack) < 16384) {
588  obstack_chunk_size (&nodeStack) = 16384;
589  }
590 #endif
591 }
592 
593 
598  decoderTree_t ret;
599 
600  if (useMalloc) {
601  CALLOC(ret, struct decoderTree, 1);
602  CALLOC(ret->children, struct decoderTree *, alphasize);
603  CALLOC(ret->transitions, struct decoderTree *, alphasize);
604  CALLOC(ret->traversed, BOOL, alphasize);
605  MALLOC(ret->count, Uint, alphasize);
606  MALLOC(ret->symbols, Uchar, alphasize);
607  }
608  else {
609 #ifndef WIN32
610  ret = (decoderTree_t)obstack_alloc(&nodeStack, sizeof(struct decoderTree));
611  memset(ret, 0, sizeof(struct decoderTree));
612 
613  ret->children = (decoderTree_t *)obstack_alloc(&nodeStack, sizeof(struct decoderTree *) * alphasize);
614  memset(ret->children, 0, sizeof(struct decoderTree *) * alphasize);
615 
616  ret->transitions = (decoderTree_t *)obstack_alloc(&nodeStack, sizeof(struct decoderTree *) * alphasize);
617  memset(ret->transitions, 0, sizeof(struct decoderTree *) * alphasize);
618 
619  ret->traversed = (BOOL *)obstack_alloc(&nodeStack, sizeof(BOOL) * alphasize);
620  memset(ret->traversed, 0, sizeof(BOOL) * alphasize);
621 
622  ret->count = (Uint *)obstack_alloc(&nodeStack, sizeof(Uint) * alphasize);
623  ret->symbols = (Uchar *)obstack_alloc(&nodeStack, sizeof(Uchar) * alphasize);
624 #else
625  CALLOC(ret, struct decoderTree, 1);
626  CALLOC(ret->children, struct decoderTree *, alphasize);
627  CALLOC(ret->transitions, struct decoderTree *, alphasize);
628  CALLOC(ret->traversed, BOOL, alphasize);
629  MALLOC(ret->count, Uint, alphasize);
630  MALLOC(ret->symbols, Uchar, alphasize);
631 #endif
632  }
633 
634  /* not always true but makes sense as init */
635  ret->left = ROOT;
636  ret->right = ROOT;
637  ret->origin = ret;
638  ret->used = False;
639 
640  return ret;
641 }
642 
643 
648 void freeDecoderTree(decoderTree_t tree, BOOL deleteText) {
649  FREE(tree->children);
650  FREE(tree->transitions);
651  FREE(tree->traversed);
652  FREE(tree->count);
653  FREE(tree->symbols);
654  if (deleteText) {
655  FREE(*(tree->text));
656  FREE(tree->text);
657  }
658  FREE(tree);
659 }
660 
661 
666  decoderTree_t *transitions;
667  Uint i;
668 
669  CALLOC(transitions, decoderTree_t, alphasize);
670  verify(tree, tree, False, False);
671  for (i=0; i<alphasize; i++) {
672  transitions[i] = tree; /* ROOT */
673  }
674  propagateTransitions (transitions, tree);
675  FREE(transitions);
676 }
677 
678 
684  decoderTree_t ret;
685  SYMBOL s;
686 
687  ret = initDecoderTree(True); /* ROOT */
688  ret->internal = True;
689  ret->internalFSM = True;
690  ret->used = True;
691 
692  s.scale = 16383;
695  s.high_count = internalNodes + 1;
696  remove_symbol_from_stream(file, &s);
697 
699  printf("Nodes: internal %d total %ld\n", internalNodes, totalNodes);
700 
701  if (internalNodes > 0) {
702  readEncoder(file); /* leo el root */
703  readDecoderTreeRec(ret, file);
704  }
705  else {
706  ret->internalFSM = False;
707  }
708 
709  return ret;
710 }
711 
712 
718  return tree->left == ROOT;
719 }
720 
721 
722 #ifdef DEBUG
723 
727 void printDecoderTree(decoderTree_t tree) {
728  printRec(tree, 0);
729 }
730 
731 #endif
struct decoderTree ** children
List of pointers to all the children of this node.
Definition: decoderTree.h:32
struct decoderTree * decoderTree_t
Decoder context tree structure.
Uchar ** text
&lt; Flag that indicates if this node is an internal node of the FSM closure of T(x) ...
Definition: decoderTree.h:43
unsigned short int scale
Definition: coder.h:24
void freeDecoderTree(decoderTree_t tree, BOOL deleteText)
Deletes a decoder tree structure instance.
Definition: decoderTree.c:648
Definition: coder.h:21
BOOL * traversed
List of flags indicating an attempt was made to traverse each child edge.
Definition: decoderTree.h:38
static void verify(const decoderTree_t root, decoderTree_t node, BOOL fast, BOOL decoder)
Verifies that the tail of node is in the tree, adding it if necessary and continuing recursively on t...
Definition: decoderTree.c:374
struct decoderTree * tail
Pointer to the node whose label is the tail of this one.
Definition: decoderTree.h:32
struct decoderTree * parent
Pointer to the parent of this node.
Definition: decoderTree.h:32
#define True
True boolean constant.
Definition: types.h:108
Uint alphasize
Alphabet size.
Definition: alpha.h:25
unsigned char Uchar
Unsigned char type.
Definition: types.h:48
Uint right
Index of the rightmost character of the label of this node.
Definition: decoderTree.h:26
BOOL internalFSM
&lt; Flag that indicates if this node is an internal node of T(x)
Definition: decoderTree.h:38
static Uint totalNodes
Total number of nodes in the tree.
Definition: decoderTree.c:40
#define ROOT
Flag to indicate a node is the root.
Definition: decoderTree.c:31
struct decoderTree * origin
Pointer to the original node this one descends from.
Definition: decoderTree.h:32
Uint left
Index of the leftmost character of the label of this node.
Definition: decoderTree.h:26
BOOL isRootDecoderTree(decoderTree_t tree)
Indicates if the parameter node is the root of the tree.
Definition: decoderTree.c:717
Uint totalSyms
Definition: decoderTree.h:26
#define FREE(P)
Frees a block of memory and makes the pointer NULL.
Definition: spacedef.h:58
#define CALLOC(S, T, N)
Allocs a new block of memory and sets all its bits to zero.
Definition: spacedef.h:72
unsigned long Uint
Unsigned int type.
Definition: types.h:54
#define BOOL
Boolean data type.
Definition: types.h:92
unsigned short int low_count
Definition: coder.h:22
void verifyDecoder(const decoderTree_t root, decoderTree_t node)
Verify*, only called by the decoder routine.
Definition: decoderTree.c:418
BOOL used
Flag that indicates if this node has been used to decode eny symbols.
Definition: decoderTree.h:38
static void canonize(decoderTree_t tree, Uint xLeft, Uint xRight, decoderTree_t node, decoderTree_t *r, Uint *uLeft, Uint *uRight, Uint *vLeft, Uint *vRight)
Calculates the canonical decomposition of a string.
Definition: decoderTree.c:109
void makeDecoderFsm(decoderTree_t tree)
Calculates the FSM closure of this tree.
Definition: decoderTree.c:665
Uchar characters[UCHAR_MAX+1]
Characters in text in alphabetical order.
Definition: alpha.h:28
#define DEBUGCODE(S)
Definition: debug.h:32
struct decoderTree ** transitions
List of FSM transitions from this state.
Definition: decoderTree.h:32
#define False
False boolean constant.
Definition: types.h:100
#define MALLOC(S, T, N)
Definition: spacedef.h:81
void initDecoderTreeStack()
Definition: decoderTree.c:584
Uint alphaindex[UCHAR_MAX+1]
Index of each alphabet character.
Definition: alpha.h:31
#define GETINDEX2(N)
Returns the index of the Nth character in the input text.
Definition: alpha.h:47
decoderTree_t initDecoderTree(BOOL useMalloc)
Creates and initializes a new decoder tree structure instance.
Definition: decoderTree.c:597
#define REALLOC(V, S, T, N)
Resizes a block of memory and prints an error message if necessary.
Definition: spacedef.h:43
unsigned short int high_count
Definition: coder.h:23
Uint * count
Counts of the number of occurrences of each symbol in this state.
Definition: decoderTree.h:26
static decoderTree_t insert(decoderTree_t r, decoderTree_t node, Uint uLeft, Uint uRight, Uint vLeft, Uint vRight, BOOL decoder)
Inserts a new node in the FSM closure of the tree.
Definition: decoderTree.c:166
static struct obstack nodeStack
Definition: decoderTree.c:43
static void propagateTransitions(decoderTree_t *transitions, decoderTree_t tree)
Adds to the FSM a set of transitions originating from tree if thew were not defined by verify...
Definition: decoderTree.c:427
void remove_symbol_from_stream(FILE *stream, SYMBOL *s)
Definition: coder.c:161
BOOL internal
Definition: decoderTree.h:38
Decoder context tree structure.
Definition: decoderTree.h:25
short int get_current_count(SYMBOL *s)
Definition: coder.c:124
Uchar * symbols
Definition: decoderTree.h:44
static Ushort internalNodes
Number of internal nodes in the tree.
Definition: decoderTree.c:37
static int readDecoderTreeRec(decoderTree_t t, FILE *file)
Reads a decoder tree from its encoded representation on a file.
Definition: decoderTree.c:496
unsigned short Ushort
Unsigned short type.
Definition: types.h:51
decoderTree_t readDecoderTree(FILE *file)
Creates a new decoder tree reading it from a file.
Definition: decoderTree.c:683
static BOOL readEncoder(FILE *file)
Reads a bit from the file using an arithmetic decoder.
Definition: decoderTree.c:448
static void fastCanonize(decoderTree_t tree, Uint xLeft, Uint xRight, decoderTree_t node, decoderTree_t *r, Uint *uLeft, Uint *uRight, Uint *vLeft, Uint *vRight)
Calculates the canonical decomposition of a string in a faster way.
Definition: decoderTree.c:60