src/Functions.cpp
/**
 * This function is basicly the Ukkonnens algorithm implementation.
 * It is called repetitively in for loop, once for each of the prefixes
 * of the input string. The prefix in question is marked with the index
 * of its last character.
 * At each prefix, start is at active point, add
 * a new edge marking the new last character, until is
 * reached a point where the new edge is not needed because to
 * the presence of an existing edge starting with the new
 * last character. This point is the end point.
 * end point is active point for the next pass through the tree.
 * It is required to update it is last_char_index to indicate
 * that it has grown by a single character, and then this
 * method can do all its work repeatevly.
 */
This function is basicly the Ukkonnens algorithm implementation.
It is called repetitively in for loop, once for each of the prefixes
of the input string. The prefix in question is marked with the index
of its last character.
At each prefix, start is at active point, add
a new edge marking the new last character, until is
reached a point where the new edge is not needed because to
the presence of an existing edge starting with the new
last character. This point is the end point.
end point is active point for the next pass through the tree.
It is required to update it is last_char_index to indicate
that it has grown by a single character, and then this
method can do all its work repeatevly.
This function is basicly the Ukkonnens algorithm implementation . It is called repetitively in for loop once for each of the prefixes of the input string . The prefix in question is marked with the index of its last character . At each prefix start is at active point add a new edge marking the new last character until is reached a point where the new edge is not needed because to the presence of an existing edge starting with the new last character . This point is the end point . end point is active point for the next pass through the tree . It is required to update it is last_char_index to indicate that it has grown by a single character and then this method can do all its work repeatevly .
void AddPrefix(Suffix &active, int last_char_index) {
    int parent_node;
    int last_parent_node = -1;
    while (true) {
        Edge edge;
        parent_node = active.origin_node;
        if (active.Explicit()) {
            edge = Edge::Find(active.origin_node, Sequence[last_char_index]);
            if (edge.start_node != -1)
                break;
        } else { 
            edge = Edge::Find(active.origin_node, Sequence[active.first_char_index]);
            int span = active.last_char_index - active.first_char_index;
            if (Sequence[edge.first_char_index + span + 1] == Sequence[last_char_index])
                break;
            parent_node = edge.SplitEdge(active);
        }
        Edge *new_edge = new Edge(last_char_index, Length, parent_node);
        new_edge->Insert();
        if (last_parent_node > 0)
            Nodes[last_parent_node].suffix_node = parent_node;
        last_parent_node = parent_node;
        if (active.origin_node == 0)
            active.first_char_index++;
        else
            active.origin_node = Nodes[active.origin_node].suffix_node;
        active.Canonize();
    }
    if (last_parent_node > 0)
        Nodes[last_parent_node].suffix_node = parent_node;
    active.last_char_index++; 
    active.Canonize();
}
void AddPrefix ( Suffix & active , int last_char_index ) { int parent_node ; int last_parent_node = -1 ; while ( true ) { Edge edge ; parent_node = active . origin_node ; if ( active . Explicit ( ) ) { edge = Edge :: Find ( active . origin_node , Sequence [ last_char_index ] ) ; if ( edge . start_node != -1 ) break ; } else { edge = Edge :: Find ( active . origin_node , Sequence [ active . first_char_index ] ) ; int span = active . last_char_index - active . first_char_index ; if ( Sequence [ edge . first_char_index + span + 1 ] == Sequence [ last_char_index ] ) break ; parent_node = edge . SplitEdge ( active ) ; } Edge * new_edge = new Edge ( last_char_index , Length , parent_node ) ; new_edge -> Insert ( ) ; if ( last_parent_node > 0 ) Nodes [ last_parent_node ] . suffix_node = parent_node ; last_parent_node = parent_node ; if ( active . origin_node == 0 ) active . first_char_index ++ ; else active . origin_node = Nodes [ active . origin_node ] . suffix_node ; active . Canonize ( ) ; } if ( last_parent_node > 0 ) Nodes [ last_parent_node ] . suffix_node = parent_node ; active . last_char_index ++ ; active . Canonize ( ) ; }
This function is basicly the Ukkonnens algorithm implementation.
This function is basicly the Ukkonnens algorithm implementation .
// Step 1 is to try and find a matching edge for the given node. // If a matching edge exists, work is done with adding edges->breake. //implicit node // Matching edge is not found -> create a new one, add // it to the tree at the parent node position, and insert it // into the hash table. // WHen new node is created then also create a suffix link to the new node from // the last node visited. // This final step isto move on the next smaller suffix.. // Eendpoint is the next active point