/* Fundamental string processing from Gusfield, Algorithms on Strings, Trees, and Sequences: Computer Science and Computational Biology, pages 8-10 */ /* Note: C string conventions are used instead of Pascal as in Gusfield Note: '$' is used as a distinguished character and should not be used in input strings to application functions */ // Developed using simpler "countdown" notion /* BPW, 8/3/04 */ #include #include #include #define ONE (1) char S[1001]; int sLength; int Z[1001]; /* Given a string S and a position i, Z[i] is the length of the longest substring of S that starts at i and matches a prefix of S. */ int min(int x,int y) { if (x=countdown) { // Possibility of extending Z-box to right with more matches while (S[scanPosition]==S[countdown]) { scanPosition++; countdown++; } // Save number of matches and move over Z[fillPosition++]=countdown; if (countdown==0) // Obviously, scanPosition can't be left behind scanPosition=fillPosition; else { // By definition of Z[], ready to copy from Z[1] countdown--; prefixPosition=1; } } else { // Z-box can't extend, so just copy Z[fillPosition++]=Z[prefixPosition++]; countdown--; } //printf("Entering second phase with fillPosition=%d\n",fillPosition); //After EOS scanned. Modified copy loop. while (fillPosition