I want to turn my Boyer - Moore algorithm into a Sunday (Quick Search). Currently I have a working version of the Boyer - Moore string search algorithm:
vector <int> table(256);
fill(table.begin(), table.end(), -1);
for (int i = 0; i < target_size; i++) {
table[(int)target[i]] = i;
}
int s = 0;
while (s <= (text_size - target_size)) {
int j = target_size - 1;
while (j >= 0 && target[j] == text[s + j])
j--;
if (j < 0) {
cout << s << endl;
s += (s + target_size < text_size) ? text_size- table[text[s + target_size]] : 1;
}
else
s += max(1, j - table[text[s + target_size]]);
}
I have been looking at the following 2 links that explain Sunday (Quick search) algorithm, but I am not exactly sure how to change B-M into Sunday:
http://www.iti.fh-flensburg.de/lang/algorithmen/pattern/sundayen.htm
http://www-igm.univ-mlv.fr/~lecroq/string/node19.html
I would appreciate any tips.