43 #define GET_RIGHT(R, T)\
45 R = T->child->left-1;\
64 if (p == -1 || p < k) {
76 kPrime = sPrime->
left;
78 while ((k <= p) && (pPrime - kPrime <= p - k)) {
79 k = k + pPrime - kPrime +1;
83 kPrime = sPrime->
left;
106 if (p != -1 && k <= p) {
108 kPrime = sPrime->
left;
116 new->left = sPrime->
left;
121 sPrime->
left = kPrime + p - k + 1;
126 if (new->parent->child == sPrime) {
149 return sPrime != NULL;
241 printf(
"root %p", tree);
246 printf(
"%ld - %ld - %p", tree->
left, right, tree);
260 for (i=1; i<level; i++) {
270 printRec(tree, level);
286 sum += treeSize(tree);
333 if (i%1000 == 0) printf(
"%ld/%ld\r", i,
textlen);
336 DEBUGCODE(printf(
"Original tree size: %d\n", treeSize(tree)));
358 if (tree->left > length) {
360 tree->stats->count[i] = 1;
361 tree->stats->symbols[tree->stats->symbolCount++] = i;
371 if (tree->left !=
ROOT) {
373 PUSHNODE(length + right - tree->left + 1);
385 if (tree->stats->count[child->
stats->
symbols[i]] == 0) {
386 tree->stats->symbols[tree->stats->symbolCount++] = child->
stats->
symbols[i];
399 tree->stats->cost += auxx;
405 if (est <= tree->stats->cost) {
406 tree->stats->cost = est;
437 fsmNode->children[
pos]->parent = fsmNode;
438 fsmNode->children[
pos]->left = tree->
left;
441 fsmNode->children[
pos]->right = tree->
left;
444 fsmNode->children[
pos]->right = right;
446 if (fsmNode->left !=
ROOT) {
447 fsmNode->children[
pos]->length = fsmNode->length + fsmNode->right - fsmNode->left + 1;
Uint * count
List with the number of occurrences of each character in this state.
static void pruneSubTree(suffixTree_t tree)
Delete a subtree from the complete tree.
#define BOTTOM
Flag to indicate a node is bottom.
void buildSuffixTree(suffixTree_t tree)
Builds a suffix tree based on the input string.
struct suffixTree * suffixTree_t
Suffix tree structure.
double escapeCost(statistics_t stats, Uint *distinct)
Calculates the cost of escapes in a node.
fsmTree_t initFsmTree()
Creates and initializes a new fsm tree structure instance.
struct suffixTree * suffix
Pointer to the node whose label is the tail of this node's label.
Uint textlen
Length of the input text in the encoder.
#define GET_RIGHT(R, T)
Gets the index of the rightmost character of this node label in the input string. ...
double hAlpha()
Returns the binary entropy of 1/alphasize.
#define True
True boolean constant.
Uint alphasize
Alphabet size.
struct suffixTree * sibling
Pointer to the next sibling of this node.
double cost
Cost assigned to this subtree.
Uchar * text
Input text to the encoder.
#define POPNODE(N)
Pops an element out of the stack.
static void update(suffixTree_t s, Uint k, Uint i, suffixTree_t *retS, Uint *retK)
Adds a new character of the input string to the evolving suffix tree.
fsmTree_t fsmSuffixTree(suffixTree_t tree)
Transforms this tree in an equivalent fsm tree structure.
#define FREE(P)
Frees a block of memory and makes the pointer NULL.
#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.
void pruneSuffixTree(suffixTree_t tree)
Prunes this suffix tree according to some cost function.
Uint symbolCount
Number of occuring symbols.
suffixTree_t initSuffixTree()
Creates and initializes a new suffix tree structure instance.
statistics_t allocStatistics()
Creates and initializes a new statistics structure instance.
Encoder context tree structure.
statistics_t stats
Pointer to the statistics for this node context.
static short pos
Current position in the buffer.
void freeSuffixTree(suffixTree_t tree)
Deletes a suffix tree structure instance.
struct fsmTree * fsmTree_t
Encoder context tree structure.
#define False
False boolean constant.
void freeStatistics(statistics_t st)
Deletes a statistics structure instance.
static void addChild(suffixTree_t s, Uint i)
Creates a new leaf on the tree.
Uchar * symbols
List of occuring symbols.
#define ROOT
Flag to indicate a node is the root.
#define INFINITY
Flag to indicate that the rightmost index of a label is the index of the last processed character of ...
#define GETINDEX(N)
Returns the index of the Nth character in the input text.
static BOOL testAndSplit(suffixTree_t s, Uint k, Uint p, suffixTree_t *r)
Tests if the input state is the end point. If it is not the end point, and it is not an explicit stat...
static void canonize(suffixTree_t s, Uint k, Uint p, suffixTree_t *retS, Uint *retK)
Given a reference for a (possibly implicit) state returns the canonical reference to the same state...
struct suffixTree * parent
Pointer to the parent of this node.
#define NOTSTACKEMPTY
Indicates if the stack is empty.
#define PUSHNODE(N)
Pushes a new item to the stack.
double nodeCost(statistics_t stats)
Calculates the cost of a node.
struct suffixTree * child
Pointer to the first child of this node.
Uint left
Index of the leftmost character of this node label in the input string.