LST_STree* lst_stree_new (LST_StringSet *strings); void lst_stree_free (LST_STree *tree); int lst_stree_init (LST_STree *tree); void lst_stree_clear (LST_STree *tree); void lst_stree_add_string (LST_STree *tree, LST_String *string); void lst_stree_remove_string (LST_STree *tree, LST_String *string); int lst_stree_get_string_index (LST_STree *tree, LST_String *string); void lst_stree_allow_duplicates (LST_STree *tree, int duplicates_flag); LST_Node* lst_node_get_parent (LST_Node *node); int lst_node_is_leaf (LST_Node *node); int lst_node_is_root (LST_Node *node); int lst_node_get_string_length (LST_Node *node); LST_String* lst_node_get_string (LST_Node *node, int max_depth); int lst_edge_get_length (LST_Edge *edge); |
LST_STree* lst_stree_new (LST_StringSet *strings); |
This is an implementation of Ukkonen's O(n) algorithm for creating a suffix tree. Upon return, the tree contains information on all the strings contained in the given string set. If you don't want to insert strings right away, just pass NULL.
set of strings to build tree with.
new suffix tree.
void lst_stree_free (LST_STree *tree); |
The function releases all the memory claimed by the suffix tree. It does not touch any of the strings contained in the tree when called, it only cleans up the tree itself. Use when the tree was created with lst_stree_new().
tree to clean up.
int lst_stree_init (LST_STree *tree); |
This function initializes a tree structure that already exists. It is hence faster when you need a suffix tree in a tight loop as no data need be allocated and later on freed. It does not check if any data is existing in the structure when called; make sure you call lst_stree_clear() when you want to use the structure repeatedly.
tree structure to initialize.
value > 0 when initialization was successful, 0 otherwise.
void lst_stree_clear (LST_STree *tree); |
This is the counterpart to lst_stree_init(). It cleans up the tree but does not free the tree structure itself.
tree to clear.
void lst_stree_add_string (LST_STree *tree, LST_String *string); |
The function adds string to the tree, unless he string is a duplicate of an existing string and duplicates are not allowed (see lst_stree_allow_duplicates()).
tree to add string to.
string to add.
void lst_stree_remove_string (LST_STree *tree, LST_String *string); |
The function checks whether tree in fact contains string and if that's the case, removes it from the tree.
tree to remove string from.
string to remove.
int lst_stree_get_string_index (LST_STree *tree, LST_String *string); |
Within a suffix tree, every string contained in it is associated with an integer index value. This function returns that value.
tree to query.
string to look up.
index of string in tree.
void lst_stree_allow_duplicates (LST_STree *tree, int duplicates_flag); |
Depending on the application of the suffix tree, it may be okay to have duplicates of strings in the tree or not. By default, duplicates are allowed. However, if you want to prevent insertion of a string that is already contained in the tree, pass 0.
tree to modify.
whether to allow duplicates (> 0) or not (0).
LST_Node* lst_node_get_parent (LST_Node *node); |
node to find parent for.
the parent node of a node, or NULL if no such node exists.
int lst_node_is_leaf (LST_Node *node); |
node to check.
value > 0 if node is a leaf, 0 otherwise.
int lst_node_is_root (LST_Node *node); |
node to check.
value > 0 if node is the root, 0 otherwise.
int lst_node_get_string_length (LST_Node *node); |
node to query.
the number of string items found on the edges iterated when going from the root down to node.
LST_String* lst_node_get_string (LST_Node *node, int max_depth); |
node whose string to return.
make string no longer than max_depth items.
A newly allocated string consisting of all the string elements found when iterating from the root down to node.