Given a m-length pattern and n-length data, and σ-length alphabet ( σ = 256 ):
$ npm install bop [-g]
var Bop = ;
$cd bop/$npm test
$ cd bop/$ npm run bench
Create an instance with a Buffer or String pattern.
// orBuffer | String pattern
Arguments within [ ] are optional.
/** List all pattern occurrences into a String or Buffer data.* It returns a new array of indexes, or populates an array* passed as the last argument.** NOTE: it is faster using Buffers.*/Bop# : Array/** Change the pattern to search.*/Bop# : Buffer
var assert =Bop =pattern = 'hellofolks\r\n\r\n'text = 'hehe' + pattern +'loremipsumhellofolks\r\n' + pattern// create a Bop instance that parses the patternbop =// parse data from beginningresults = bopbresults = null;// change patternbop;// re-parse data passing a Buffer instead of a Stringbresults = bop;// results are the sameassert;// parser results ( starting indexes ) [ 4, 40 ]console;
Parser uses 3 Buffers 256-bytes long to build shifting tables, then:
- Pattern parsing / table creation space and time complexity is O(σ).
- Very low memory footprint.
- Ultra fast to preprocess pattern ( = tables creation ).
$ node bench/small-pattern-data-rate
for default it:
- uses a pattern string of 57 bytes/chars.
- builds a data buffer of 700 MB in memory.
- uses a redundancy/distance factor for pattern strings equal to 2. The bigger the value, the lesser are occurrences of pattern string into the text buffer.
# with [testBufferSizeInMB] [distanceFactor] [aStringPattern]$ node bench/small-pattern-data-rate.js 700 4 "that'sallfolks"
Parser uses 3 arrays to build shifting tables for big patterns, then:
- there will be an high memory consumption, due to the use of arrays.
- it will take a long time to preprocess pattern ( = tables creation ).
$ node bench/big-pattern-data-rate
- it uses a very big pattern ( 20 MBytes ).
- it builds a data buffer of 300 MBytes, copying the same pattern 12 times.
See bench dir.
Copyright (c) 2015-present < Guglielmo Ferri : email@example.com >
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.