{"id":17771411,"url":"https://github.com/rootslab/qap","last_synced_at":"2025-07-29T21:39:24.919Z","repository":{"id":5250640,"uuid":"6428311","full_name":"rootslab/qap","owner":"rootslab","description":"Qap is a quick parser/matcher for string or buffer patterns ( optimized for pattern lengths \u003c= 255 bytes ).","archived":false,"fork":false,"pushed_at":"2018-02-10T14:41:14.000Z","size":93,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-17T00:30:34.674Z","etag":null,"topics":["pattern-matching","quicksearch","search-algorithm"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"django-haystack/django-haystack","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rootslab.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-10-28T14:34:14.000Z","updated_at":"2017-11-08T23:42:29.000Z","dependencies_parsed_at":"2022-09-06T13:40:29.792Z","dependency_job_id":null,"html_url":"https://github.com/rootslab/qap","commit_stats":null,"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"purl":"pkg:github/rootslab/qap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootslab%2Fqap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootslab%2Fqap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootslab%2Fqap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootslab%2Fqap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rootslab","download_url":"https://codeload.github.com/rootslab/qap/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rootslab%2Fqap/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267764257,"owners_count":24140839,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pattern-matching","quicksearch","search-algorithm"],"created_at":"2024-10-26T21:32:47.177Z","updated_at":"2025-07-29T21:39:24.868Z","avatar_url":"https://github.com/rootslab.png","language":"JavaScript","readme":"### Qap\n\n[![NPM VERSION](http://img.shields.io/npm/v/qap.svg?style=flat)](https://www.npmjs.org/package/qap)\n[![CODACY BADGE](https://img.shields.io/codacy/b18ed7d95b0a4707a0ff7b88b30d3def.svg?style=flat)](https://www.codacy.com/public/44gatti/qap)\n[![CODECLIMATE-TEST-COVERAGE](https://img.shields.io/codeclimate/c/rootslab/qap.svg?style=flat)](https://codeclimate.com/github/rootslab/qap)\n[![LICENSE](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/rootslab/qap#mit-license)\n\n![NODE VERSION](https://img.shields.io/node/v/qap.svg)\n[![TRAVIS CI BUILD](http://img.shields.io/travis/rootslab/qap.svg?style=flat)](http://travis-ci.org/rootslab/qap)\n[![BUILD STATUS](http://img.shields.io/david/rootslab/qap.svg?style=flat)](https://david-dm.org/rootslab/qap)\n[![DEVDEPENDENCY STATUS](http://img.shields.io/david/dev/rootslab/qap.svg?style=flat)](https://david-dm.org/rootslab/qap#info=devDependencies)\n\n[![NPM MONTHLY](http://img.shields.io/npm/dm/qap.svg?style=flat)](http://npm-stat.com/charts.html?package=qap)\n![NPM YEARLY](https://img.shields.io/npm/dy/qap.svg)\n\n[![NPM GRAPH](https://nodei.co/npm/qap.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/qap/)\n\n\n * __Qap__ is a quick parser for string or buffer patterns. \n * It is optimized for using with pattern strings \u003c= 255 bytes.\n * Better results are achieved with long and sparse patterns.\n * It is an implementation of QuickSearch algorithm.\n\n### Main features\n\n\u003e Given a m-length pattern and n-length data and σ-length alphabet ( σ = 256 ):\n\n - simplification of the Boyer-Moore algorithm ( *see [Bop](https://github.com/rootslab/bop)* ).\n - uses only a bad-character shift table.\n - preprocessing phase in __O(m+σ)__ time and __O(σ)__ space complexity.\n - searching phase in __O(m*n)__ time complexity.\n - very fast in practice for short patterns and large alphabets.\n\n\u003e See __[Lecroq](http://www-igm.univ-mlv.fr/~lecroq/string/node19.html)__ for reference and also __[Bop](https://github.com/rootslab/bop)__, a Boyer-Moore parser.\n\n### Install\n```bash\n$ npm install qap [-g]\n```\n\n\u003e __require__:\n\n```javascript\nvar Qap = require( 'qap' );\n```\n\n### Run Tests\n\n```javascript\n$cd qap/\n$npm test\n```\n\n### Run Benchmarks\n\n```bash\n$ cd qap/\n$ npm run-script bench\n```\n\n### Constructor\n\n\u003e Create an instance with a Buffer or String pattern.\n\n```javascript\nQap( Buffer || String pattern )\n// or\nneq Qap( Buffer || String pattern )\n```\n\n### Methods\n\n\u003e List all pattern occurrences into a String or Buffer data.\n\u003e It returns a new array of indexes, or populates an array passed as the last argument to parse method.\n\n```javascript\n// slower with String\nQap#parse( String data [, Number startFromIndex [, Number limitResultsTo [, Array array ] ] ] ) : Array\n\n// faster with Buffer\nQap#parse( Buffer data [, Number startFromIndex [, Number limitResultsTo [, Array array ] ] ] ) : Array\n```\n\n\u003e Change the pattern :\n\n```javascript\nQap#set( Buffer || String pattern ) : Buffer\n```\n\n### Usage Example\n\n```javascript\nvar log = console.log\n    , assert = require( 'assert' )\n    , Qap = require( 'qap' )\n    , pattern = 'hellofolks\\r\\n\\r\\n'\n    , text = 'hehe' + pattern +'loremipsumhellofolks\\r\\n' + pattern\n    , bresult = null\n    ;\n\n// create an instance and parse the pattern\nvar qap = Qap( pattern )\n    // parse data from beginning\n    , results = qap.parse( text )\n    ;\n\n// set a new Buffer pattern\nqap.set( new Buffer( pattern ) );\n\n// parse data Buffer instead of a String\nbresults = qap.parse( new Buffer( text ) );\n\n// parser results ( starting indexes ) [ 4, 40 ]\nlog( results, bresults );\n\n// results are the same\nassert.deepEqual( results, bresults );\n\n```\n\n#### Benchmark for a small pattern ( length \u003c= 255 bytes )\n\n\u003e Parser uses a Buffer 256-bytes long to build the shifting table, then:\n\n\u003e - Pattern parsing / table creation space and time complexity is O(σ).\n\u003e - Very low memory footprint.\n\u003e - Ultra fast to preprocess pattern ( = table creation ).\n\n```bash\n  $ node bench/small-pattern-data-rate\n```\n\nfor default it:\n\n\u003e - uses a pattern string of 57 bytes/chars\n\u003e - builds a data buffer of 700 MB in memory\n\u003e - uses a redundancy/distance factor for pattern strings equal to 2. The bigger the value, \nthe lesser are occurrences of pattern string into the text buffer.\n\n **Custom Usage**:\n\n```bash\n  # with [testBufferSizeInMB] [distanceFactor] [aStringPattern]\n  $ node bench/small-pattern-data-rate.js 700 4 \"that'sallfolks\"\n```\n\n#### Benchmark for a big pattern ( length \u003e 255 bytes )\n\n\u003e Parser uses one Array to build the shifting table for a big pattern, then:\n\n\u003e - table has a size of 256 elements, every element is an integer value that\n\u003e could be between 0 and the pattern length.\n\u003e - Fast to preprocess pattern ( = table creation ).\n\u003e - Low memory footprint\n\n```bash\n  $ node bench/big-pattern-data-rate\n```\n\n\u003e - it uses a pattern size of 20MB\n\u003e - builds a data buffer of 300MB copying pattern 12 times\n\nSee __[bench](./bench)__ dir.\n\n### MIT License\n\n\u003e Copyright (c) 2013-present \u0026lt; Guglielmo Ferri : 44gatti@gmail.com \u0026gt;\n\n\u003e Permission is hereby granted, free of charge, to any person obtaining\n\u003e a copy of this software and associated documentation files (the\n\u003e 'Software'), to deal in the Software without restriction, including\n\u003e without limitation the rights to use, copy, modify, merge, publish,\n\u003e distribute, sublicense, and/or sell copies of the Software, and to\n\u003e permit persons to whom the Software is furnished to do so, subject to\n\u003e the following conditions:\n\n\u003e __The above copyright notice and this permission notice shall be\n\u003e included in all copies or substantial portions of the Software.__\n\n\u003e THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\n\u003e EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n\u003e MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n\u003e IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n\u003e CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n\u003e TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n\u003e SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frootslab%2Fqap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frootslab%2Fqap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frootslab%2Fqap/lists"}