Efficient string matching algorithm

后端 未结 14 855
Happy的楠姐
Happy的楠姐 2020-12-16 07:13

I\'m trying to build an efficient string matching algorithm. This will execute in a high-volume environment, so performance is critical.

Here are my requirements:

14条回答
  •  暖寄归人
    2020-12-16 08:02

    Investigate the KMP (Knuth-Morris-Pratt) or BM (Boyer-Moore) algorithms. These allow you to search the string more quickly than linear time, at the cost of a little pre-processing. Dropping the leading asterisk is of course crucial, as others have noted.

    One source of information for these is:

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

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

提交回复
热议问题