All Projects → rootslab → bop

rootslab / bop

Licence: MIT license
Bop is a very fast Boyer-Moore parser/matcher for String or Buffer patterns.

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to bop

montre
The original timed regular expression matcher over temporal behaviors
Stars: ✭ 14 (-6.67%)
Mutual labels:  pattern-matching
js-algorithms
Computer science
Stars: ✭ 64 (+326.67%)
Mutual labels:  search-algorithm
librxvm
non-backtracking NFA-based regular expression library, for C and Python
Stars: ✭ 57 (+280%)
Mutual labels:  pattern-matching
pmatch
Pattern matching DSL for R
Stars: ✭ 21 (+40%)
Mutual labels:  pattern-matching
CVparser
CVparser is software for parsing or extracting data out of CV/resumes.
Stars: ✭ 28 (+86.67%)
Mutual labels:  pattern-matching
squire
The medieval language held together by twine.
Stars: ✭ 42 (+180%)
Mutual labels:  pattern-matching
sweet-egison
Haskell library for non-deterministic pattern matching
Stars: ✭ 15 (+0%)
Mutual labels:  pattern-matching
Sig
The most powerful and customizable binary pattern scanner
Stars: ✭ 131 (+773.33%)
Mutual labels:  pattern-matching
suitcase
Java Pattern Matching library
Stars: ✭ 21 (+40%)
Mutual labels:  pattern-matching
Intelligent Document Finder
Document Search Engine Tool
Stars: ✭ 45 (+200%)
Mutual labels:  search-algorithm
monster-avengers
Monster Hunter Armor Searcher
Stars: ✭ 24 (+60%)
Mutual labels:  search-algorithm
wink-nlp
Developer friendly Natural Language Processing ✨
Stars: ✭ 312 (+1980%)
Mutual labels:  pattern-matching
go-pattern-match
Pattern matchings for Go.
Stars: ✭ 182 (+1113.33%)
Mutual labels:  pattern-matching
Differentia.js
No longer being supported or maintained. A Graph Theory & Data Structure Library for JavaScript.
Stars: ✭ 13 (-13.33%)
Mutual labels:  search-algorithm
Project-1-Search-in-Pacman
Search algorithms(BFS, DFS, UCS, A*) in python.Berkeley Pacman Project 1.
Stars: ✭ 20 (+33.33%)
Mutual labels:  search-algorithm
egison-haskell
Template Haskell Implementation of Egison Pattern Matching
Stars: ✭ 31 (+106.67%)
Mutual labels:  pattern-matching
bool-expr-indexer
A fast boolean expression index implementation, especially for RTB ad selection. A Go implementation of the core algorithm in paper <Indexing Boolean Expression>
Stars: ✭ 49 (+226.67%)
Mutual labels:  search-algorithm
indexer4j
Simple full text indexing and searching library for Java
Stars: ✭ 47 (+213.33%)
Mutual labels:  search-algorithm
pynpuzzle
Solve, test and benchmark algorithms for N-Puzzle problem with Python
Stars: ✭ 26 (+73.33%)
Mutual labels:  search-algorithm
RustLabs
The Ultimate Workshop Track for #Rust Developer
Stars: ✭ 22 (+46.67%)
Mutual labels:  pattern-matching

Bop

NPM VERSION CODACY BADGE CODECLIMATE-TEST-COVERAGE LICENSE

NODE VERSION TRAVIS CI BUILD BUILD STATUS DEVDEPENDENCY STATUS

NPM MONTHLY NPM YEARLY NPM TOTAL

NPM GRAPH

  • Bop is a very fast Boyer-Moore parser for string or buffer patterns.
  • It is optimized for using with pattern strings/buffers <= 255 bytes.
  • It is ideal, for example, to parse streams like multipart/form-data ones, in which pattern/boundary length < ~70 bytes).

Main features

Given a m-length pattern and n-length data, and σ-length alphabet ( σ = 256 ):

  • it performs the comparisons from right to left.
  • preprocessing phase in O(m+σ) time and space complexity.
  • searching phase in O(m*n) time complexity.
  • 3*n text character comparisons in the worst case when searching for a non periodic pattern.
  • O(n/m) best performance.

See Lecroq for reference and also Qap, a QuickSearch parser.

Install

$ npm install bop [-g]

require:

var Bop = require( 'bop' );

Run Tests

$cd bop/
$npm test

to execute a single test file simply do:

 $ node test/file-name.js

Run Benchmarks

$ cd bop/
$ npm run bench

Constructor

Create an instance, using a pattern.

Bop( Buffer pattern | String pattern )
// or
new Bop( Buffer pattern | String pattern )

Methods

Arguments within [] are optional.

// Change the pattern to search.
Bop#set( Buffer pattern | String pattern ) : Buffer

/*
 * Count matches, optionally starting from a particular index (default
 * is 0). It returns an Array containing the number of matches, and the
 * remaining bytes
 */
Bop#count( Buffer data [, Number start_from ] ) : Array

// Same as #count, but without counting overlapping sequences
Bop#scount( Buffer data [, Number start_from ] ) : Array

/*
 * Count matches, and the max distance found between 2 matches,
 * optionally starting from a particular index (default is 0).
 * It returns an Array containing:
 * - the number of matches
 * - the max distance found between 2 matches, -1 otherwise
 * - the distance from data index 0 to the first match, -1 otherwise
 * - the distance from the end of the last match to the end of data,
 *   -1 otherwise
 * 
 * NOTE: if 0 or only 1 occurrence was found, the max distance will
 * be -1 and then the resulting array will be respectvely:
 * - [0, -1, -1, -1 ]
 * - [1, -1, .., .. ]
 */
Bop#dist( Buffer data [, Number start_from ] ) : Array

// same as #dist, but without counting overlapping sequences
Bop#sdist( Buffer data [, Number start_from ] ) : Array

/*
 * Collect all indexes of pattern occurrences.
 *
 * As options you can:
 *
 * - start parsing from a particular index
 * - limit the number of results to parse
 * - fill your array with resulting indexes.
 *
 * NOTE: use Buffers when possible (faster).
 *
 */
Bop#parse( Buffer data | String data [, Number start_from [, Number limit_results [, Array my_array ] ] ] ) : Array

/*
 * Strict parse, it's the same as parse, without collecting
 * any overlapping sequences.
 *
 * Example with CRLF sequence:
 *
 * - bop pattern is set to: "\r\n\r\n"                 (CR LF CR LF)
 * - data to parse is:      "\r\n\r\n\r\n\r\n\r\n\r\n" (CR LF CR LF CR LF CR LF )
 * 
 * - with Bop.parse( data ) we get 3 indexes as results: [0, 2, 4]
 *
 *       0  1  2  3  4  5  6  7
 *      -----------------------
 *   p: CR LF CR LF
 *   d: CR LF CR LF CR LF CR LF
 *
 *   p: ----> CR LF CR LF
 *   d: CR LF CR LF CR LF CR LF
 *
 *   p: ----------> CR LF CR LF
 *   d: CR LF CR LF CR LF CR LF
 *
 * - with Bop.sparse( data ) we get only 2 results: [0, 4]
 *
 *       0  1  2  3  4  5  6  7
 *      -----------------------
 *   p: CR LF CR LF
 *   d: CR LF CR LF CR LF CR LF
 *
 *   p: ----------> CR LF CR LF
 *   d: CR LF CR LF CR LF CR LF
 *
 */
Bop#sparse( Buffer data | String data [, Number start_from [, Number limit_results [, Array my_array ] ] ] ) : Array

Usage Example

var Bop = require( 'bop' )
    , pattern = 'hellofolks\r\n'
    , somedata = 'hehehe' + pattern +'eheheh' + pattern
    , bop = Bop( pattern )
    // parse data from beginning
    , results = bop.parse( somedata )
    ;

See examples.

Benchmark for a short pattern ( length <= 255 bytes )

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.

Custom Usage:

  # with [testBufferSizeInMB] [distanceFactor] [aStringPattern]
  $ node bench/small-pattern-data-rate.js 700 4 "that'sallfolks"

Benchmark for a big pattern ( length > 255 bytes )

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.

MIT License

Copyright (c) 2013-present < Guglielmo Ferri : [email protected] >

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].