algo/kmp

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

KMP string search algorithm

dev-master 2016-04-09 14:40 UTC

This package is auto-updated.

Last update: 2021-09-29 01:53:52 UTC


README

Build Status

Requirement

  • PHP ^5.3

Install

phpize 
make
make install

Usage

kmp_search(string haystack, string needle)

Return value: (int) This function returns -1 if needle is not found in haystack.

$pos = kmp_search("zjifeoabcabcjiefjie", "abcabc");

kmp_prefix(string needle)

Return value: (resource) This function returns a resource of pre-computed prefixes array. The returned resource can be reused when there are multiple haystacks to be searched.

$prefix = kmp_prefix("abcabc");
$pos = kmp_search_prefix("zjifeoabcabcjiefjie", $prefix);

References

License

Released under MIT license