Code Monkey home page Code Monkey logo

lua-aho-corasick's Introduction

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.

lua-aho-corasick's People

Contributors

dkg avatar ghedo avatar granpc avatar hundredwatt avatar jdesgats avatar jgrahamc avatar p0pr0ck5 avatar robert-nix avatar vcunat avatar yangshuxin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lua-aho-corasick's Issues

FFI Example Usage

Hi,

Can you provide an example of using this via FFI (e.g. via libac.so)?

how get all patterns that match that given subject string

Hi,

I noticed that The Match_Tmpl not supports MV_ALL_MATCHES.

if (state->is_term) {
     if (variant == MV_FIRST_MATCH) {
         ac_result_t r;
         r.match_begin = idx - state->depth;
         r.match_end = idx - 1;
         r.pattern_idx = state->is_term - 1;
         return r;
     }

     if (variant == MV_LEFT_LONGEST) {
         int match_begin = idx - state->depth;
         int match_end = idx - 1;

         if (r.match_begin == -1 ||
             match_end - match_begin > r.match_end - r.match_begin) {
             r.match_begin = match_begin;
             r.match_end = match_end;
             r.pattern_idx = state->is_term - 1;
         }
         continue;
     }

     ASSERT(false && "NYI");
 }

What should I do if i want get all patterns that match that given subject
string? Why not implement variant == MV_ALL_MATCHES?

macos compile

it is not supported by macos, so I hope you it can be compatible for macos

License?

License? Copyright headers? Is it cloudflare's original code or a copy of a third party library?

about load_ac.lua

when I use load_ac.lua in macos, sometimes it will report and generate core file
malloc: *** error for object 0x7f8bbc831400: incorrect checksum for freed object - object was probably modified after being freed

CFLAGS etc.

When I see things like -msse4.1 in ./Makefile, I wonder whether you intend the master branch of this repo for general-purpose usage, e.g. ending up in distribution packages. Should I make similar changes in a fork or shall we generalize it directly here, perhaps in a way that you might keep injecting such flags somehow?

Currently the binaries will end up in knot-resolver packages with these flags (even on ARM :) I suspect this will be a real problem for x86 systems without SSE 4.1, and most users surely won't notice a significant difference in speed if we drop these flags. (I understand you might notice the difference on CloudFlare servers.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.