Skip to content

OC的字符串匹配库.包含KMP匹配 ,AC 多模字符串匹配.

License

Notifications You must be signed in to change notification settings

GIKICoder/GMatcherExpression

Repository files navigation

GMatcherExpression

包含KMP匹配 ,AC 多模字符串匹配.

self.searchKeywords = @[@"牛逼",@"屌丝",@"程序员"];
self.searchStr = @"xx是一个牛逼的屌丝程序员";

输出:
{5, 2},牛逼
{8, 2},屌丝
{10, 3},程序员
/// KMP 匹配
GMatcherExpression * KMP = [GMatcherExpression matcherExpressionWithPatterns:self.searchKeywords option:GMatchingOption_KMP];
NSArray * kmps = [KMP matchesInString:self.searchStr];
/// AC 多模匹配
GMatcherExpression * AC = [GMatcherExpression matcherExpressionWithPatterns:self.searchKeywords option:GMatchingOption_AC];
NSArray * ACS = [AC matchesInString:self.searchStr];
/// 均支持block 回调
[AC enumerateMatchesInString:self.searchStr usingBlock:^(GMatcherResult *result, BOOL *stop) {

}];
1万字20个匹配串
匹配效率对比(ms):
KMP:
excute time:0.202863
AC:
excute time:0.008575

About

OC的字符串匹配库.包含KMP匹配 ,AC 多模字符串匹配.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published