-
Notifications
You must be signed in to change notification settings - Fork 2
String pattern matching with transition table (finite automata)
Rafiul Islam edited this page Nov 23, 2018
·
5 revisions
// tracker index for row value copy
int track = 0;
// iteration index
int row, col;
// for first row of the table
for(col=0; col<CHARACTERS; col++)
tabl[0][col] = 0;
// update the next index of first character from the pattern
tabl[0][patt[0]] = 1;
for(row=1; row<=patt_len; row++)
{
// copy row value from tracker row
for(col=0; col<CHARACTERS; col++)
tabl[row][col] = tabl[track][col];
// set next state for current index character
tabl[row][patt[row]] = row+1;
// last row will copy the first row value for re-checking
if(row<patt_len)
track = tabl[track][patt[row]];
}