1.0.0 • Published 4 years ago
buffer-horspool v1.0.0
Buffer-Horspool
Note
Node's builtin buffer.indexOf() and typed array .indexOf() are way
faster than this nowadays – this was originally written before either of those
existed, so you probably don't want to use this, unless you know you need it.
What is this?
A simple implementation of the Boyer-Moore-Horspool string search algorithm for use with Buffers or Uint8Arrays.
Why is this?
I needed it for one of my projects in the days before buffer.indexOf() existed, wrote a gist,
others kept finding it useful, so now it's on npm.
Shoutout to @dubiousjim for finding a bug in the original gist!
Installation
$ npm install --save buffer-horspoolUsage
var horspool = require( 'buffer-horspool' )Just like the native .indexOf() methods, given a haystack and a needle,
either the index at which the substring is found is returned, otherwise -1:
var index = horspool.indexOf( haystack: Buffer|Uint8Array, needle: Buffer|Uint8Array, startOffset: Number )1.0.0
4 years ago