Context algorithm
Semi-predictive context algorithm implementation
 All Data Structures Files Functions Variables Typedefs Macros Pages
suffixTree.c File Reference
#include <stdlib.h>
#include "suffixTree.h"
#include "stack.h"
#include "alpha.h"
#include "text.h"
#include "gammaFunc.h"
#include "spacedef.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define INFINITY   -3
 Flag to indicate that the rightmost index of a label is the index of the last processed character of the input string. More...
 
#define BOTTOM   -2
 Flag to indicate a node is bottom. More...
 
#define ROOT   -1
 Flag to indicate a node is the root. More...
 
#define GET_RIGHT(R, T)
 Gets the index of the rightmost character of this node label in the input string. More...
 

Functions

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. More...
 
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 state it is made explicit by splitting a transition. More...
 
static void addChild (suffixTree_t s, Uint i)
 Creates a new leaf on the tree. More...
 
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. More...
 
static void pruneSubTree (suffixTree_t tree)
 Delete a subtree from the complete tree. More...
 
suffixTree_t initSuffixTree ()
 Creates and initializes a new suffix tree structure instance. More...
 
void freeSuffixTree (suffixTree_t tree)
 Deletes a suffix tree structure instance. More...
 
void buildSuffixTree (suffixTree_t tree)
 Builds a suffix tree based on the input string. More...
 
void pruneSuffixTree (suffixTree_t tree)
 Prunes this suffix tree according to some cost function. More...
 
fsmTree_t fsmSuffixTree (suffixTree_t tree)
 Transforms this tree in an equivalent fsm tree structure. More...
 

Macro Definition Documentation

#define BOTTOM   -2

Flag to indicate a node is bottom.

Definition at line 33 of file suffixTree.c.

#define GET_RIGHT (   R,
 
)
Value:
if (T->child) {\
R = T->child->left-1;\
}\
else {\
R = INFINITY;\
}\
#define INFINITY
Flag to indicate that the rightmost index of a label is the index of the last processed character of ...
Definition: suffixTree.c:30

Gets the index of the rightmost character of this node label in the input string.

Parameters
[out]Rthe rightmost index.
[in]Ttree node.

Definition at line 43 of file suffixTree.c.

#define INFINITY   -3

Flag to indicate that the rightmost index of a label is the index of the last processed character of the input string.

Definition at line 30 of file suffixTree.c.

#define ROOT   -1

Flag to indicate a node is the root.

Definition at line 36 of file suffixTree.c.

Function Documentation

static void addChild ( suffixTree_t  s,
Uint  i 
)
static

Creates a new leaf on the tree.

Parameters
[in]sparent of the new leaf to create.
[in]iindex of the leftmost character of the new node label.

Definition at line 159 of file suffixTree.c.

void buildSuffixTree ( suffixTree_t  tree)

Builds a suffix tree based on the input string.

Parameters
[in,out]treean empty and initialized suffix tree.

Definition at line 325 of file suffixTree.c.

static void canonize ( suffixTree_t  s,
Uint  k,
Uint  p,
suffixTree_t retS,
Uint retK 
)
static

Given a reference for a (possibly implicit) state returns the canonical reference to the same state.

Parameters
[in]sexplicit state of the tree.
[in]kindex of the leftmost character of the string from s to the state.
[in]pindex of the rightmost character of the string from s to the state.
[out]retSnew explicit state that is the closest ancestor of the state to canonize.
[out]retKindex of the leftmost character of the string from retS to the state to canonize.

Definition at line 60 of file suffixTree.c.

void freeSuffixTree ( suffixTree_t  tree)

Deletes a suffix tree structure instance.

Parameters
[in,out]treethe tree to delete.

Definition at line 317 of file suffixTree.c.

fsmTree_t fsmSuffixTree ( suffixTree_t  tree)

Transforms this tree in an equivalent fsm tree structure.

Parameters
[in]treethe tree to transform.
Returns
a new fsm tree equivalent tho the input one.

Definition at line 422 of file suffixTree.c.

suffixTree_t initSuffixTree ( )

Creates and initializes a new suffix tree structure instance.

Returns
a new an initilized tree.

Definition at line 298 of file suffixTree.c.

static void pruneSubTree ( suffixTree_t  tree)
static

Delete a subtree from the complete tree.

Parameters
[in]treesubtree to delete.

Definition at line 210 of file suffixTree.c.

void pruneSuffixTree ( suffixTree_t  tree)

Prunes this suffix tree according to some cost function.

Parameters
[in,out]treethe tree to prune.

Definition at line 343 of file suffixTree.c.

static BOOL testAndSplit ( suffixTree_t  s,
Uint  k,
Uint  p,
suffixTree_t r 
)
static

Tests if the input state is the end point. If it is not the end point, and it is not an explicit state it is made explicit by splitting a transition.

Parameters
[in]sexplicit state of the tree.
[in]kindex of the leftmost character of the string from s to the state.
[in]pindex of the rightmost character of the string from s to the state.
[out]rnew explicit state created or s if a new node was not needed.
Returns
True if the input state is the end point.

Definition at line 102 of file suffixTree.c.

static void update ( suffixTree_t  s,
Uint  k,
Uint  i,
suffixTree_t retS,
Uint retK 
)
static

Adds a new character of the input string to the evolving suffix tree.

Parameters
sexplicit node on the tree that is the closest ancestor to the active point.
kindex of the leftmost character of the string from s to the active point.
iinteger such that (i-1) is the index of the rightmost character of the string from s to the active point.
retSexplicit node on the tree that is an ancestor of the end point.
retKindex of the leftmost character of the string from retS to the end point.

Definition at line 184 of file suffixTree.c.