aho-corasick php,lua-aho-corasick

aho-corasick-lua

C++ and Lua Implementation of the Aho-Corasick (AC) string matching algorithm

(http://dl.acm.org/citation.cfm?id=360855).

We began with pure Lua implementation and realize the performance is not

satisfactory. So we switch to C/C++ implementation.

There are two shared objects provied by this package: libac.so and ahocorasick.so

The former is a regular shared object which can be directly used by C/C++

application, or by Lua via FFI; and the later is a Lua module. An example usage

is shown below:

local ac = require "ahocorasick"

local dict = {"string1", "string", "etc"}

local acinst = ac.create(dict)

local r = ac.match(acinst, "mystring")

For efficiency reasons, the implementation is slightly different from the

standard AC algorithm in that it doesn't return a set of strings in the dictionary

that match the given string, instead it only returns one of them in case the string

matches. The functionality of our implementation can be (precisely) described by

following pseudo-c snippet.

string foo(input-string, dictionary) {

string ret = the-end-of-input-string;

for each string s in dictionary {

// find the first occurrence match sub-string.

ret = min(ret, strstr(input-string, s);

}

return ret;

}

It's pretty easy to get rid of this limitation, just to associate each state with

a spare bit-vector depicting the set of strings recognized by that state.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值