Skip to content
KMP searching algorithm in mruby
Ruby
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
mrblib
test
README.md
mrbgem.rake

README.md

KMP searching algorithm in mruby

Using with mruby

Make a local copy of the mruby git tree, add the gem in your build_config.rb:

conf.gem :github => 'santazhang/mruby-kmp', :branch => 'master'

And then just build mruby with rake.

Usage

kmp = KMP.new 'needle'
p kmp.match_first('finding a needle in a haystack')
# => 10

kmp = KMP.new [1, 2, 3]
p kmp.match_all([0, 1, 2, 3, 1, 2, 3])
# => [1, 4]

kmp = KMP.new 'rr'
p kmp.match_all('rrrr')
# => [0, 1, 2]
p kmp.match_all('rrrr', overlap=false)
# => [0, 2]
You can’t perform that action at this time.