| Package | org.servebox.toolbox.search |
| Class | public class StringComparator |
The Boyer-Moore algorithm is considered as the most efficient string-matching algorithm in usual applications, and has the following features :
- performs the comparisons from right to left
- pre-processing phase in Ο(m+σ) time and space complexity
- searching phase in Ο(mn) time complexity
- 3n text character comparisons in the worst case when searching for a non-periodic pattern
The ZT algorithm is a variant of the Boyer-Moore algorithm, and has the following features :
- use two consecutive text characters to compute the bad-character shift
- pre-processing phase in Ο(m+σ²) time and space complexity
- searching phase in Ο(mn) time complexity
References :
- Boyer, R. S., and Moore, J. S., 1977. A fast string searching algorithm. Comm. ACM. 20:762-772.
- Charras, C. and Leroq. T., 1998. Exact string matching algorithms. Laboratoire d'Informatique de Rouen, Université de Rouen, 76821 Mont Saint-Aignan Cedex, France.
- Doyle B. Myers, java implementation of Boyer-Moore text search.
Usage :
if you want to search for the string abc inside the string asdadbsrsbbbfbebebrdfvdfbvabc:
StringComparator.prepareZt( "abc" );
We use the "prepare-and-go" to avoid to pre-process multiple times if you need to search inside more than one string using the same pattern.
var result:Boolean = StringComparator.zhuTakaokaMatch( "asdadbsrsbbbfbebebrdfvdfbvabc" );
// or
StringComparator.prepareBm( "abc" );
var result:Boolean = StringComparator.boyerMooreMatch( "asdadbsrsbbbfbebebrdfvdfbvabc" );
| Property | Defined by | ||
|---|---|---|---|
| ALPHABET_SIZE : Number = 256 [static]
ASCII alphabet size (64k).
| StringComparator | ||
| Method | Defined by | ||
|---|---|---|---|
|
boyerMooreMatch(text:String):Boolean
[static]
Performs a BM string-matching search for the string pattern inside the string text.
| StringComparator | ||
|
prepareBm(pattern:String):void
[static]
Pre-process pattern for Boyer-Moore matching.
| StringComparator | ||
|
prepareZt(pattern:String):void
[static]
Pre-process pattern for Zhu-Takaoka matching.
| StringComparator | ||
|
zhuTakaokaMatch(text:String):Boolean
[static]
Performs a ZT string-matching search for the string pattern inside the string text.
To use this algorithm, pattern length must be greater than 1 !!! | StringComparator | ||
| ALPHABET_SIZE | property |
public static var ALPHABET_SIZE:Number = 256ASCII alphabet size (64k).
| boyerMooreMatch | () | method |
public static function boyerMooreMatch(text:String):Boolean
Performs a BM string-matching search for the string pattern inside the string text.
text:String |
Boolean — true if pattern inside text.
|
| prepareBm | () | method |
public static function prepareBm(pattern:String):voidPre-process pattern for Boyer-Moore matching.
Parameterspattern:String |
| prepareZt | () | method |
public static function prepareZt(pattern:String):voidPre-process pattern for Zhu-Takaoka matching.
Parameterspattern:String |
| zhuTakaokaMatch | () | method |
public static function zhuTakaokaMatch(text:String):Boolean
Performs a ZT string-matching search for the string pattern inside the string text.
To use this algorithm, pattern length must be greater than 1 !!!
text:String |
Boolean — true if pattern inside text.
|