1

我想把我的 Boyer - Moore 算法变成星期天(快速搜索)。目前我有一个工作版本的 Boyer - Moore 字符串搜索算法:

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]]);
}

我一直在查看以下 2 个解释星期日(快速搜索)算法的链接,但我不确定如何将 BM 更改为星期日:

http://www.iti.fh-flensburg.de/lang/algorithmen/pattern/sundayen.htm

http://www-igm.univ-mlv.fr/~lecroq/string/node19.html

我会很感激任何提示。

4

0 回答 0