Package Exports
- bloomrun
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bloomrun) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
bloomrun
A js pattern matcher based on bloom filters, inspired by patrun. But different: 10x faster, and with results that can be returned in insertion order or depth order.
Install
To install bloomrun, simply use npm:
npm install bloomrun --save
Example
The example below can be found here and ran using node example.js. It
demonstrates how to use bloomrun for pattern matching with a payload.
'use strict'
var bloomrun = require('bloomrun')()
bloomrun.add({say: 'hello' }, 'Hello World!')
bloomrun.add({say: 'goodbye'}, function () {
console.log('Goodbye World!')
})
var hello = bloomrun.lookup({say: 'hello'})
console.log(hello)
var goodbye = bloomrun.lookup({say: 'goodbye'})
goodbye()API
bloomrun([opts])
Creates a new instance of Bloomrun.
Options are:
indexing: it can be eitherinsertion(default) ordepth; if set toinsertion, it will try to match entries in insertion order; if set todepth, it will try to match entries with the most properties first.
instance.add(pattern [,payload])
Adds a pattern to the Bloomrun instance. You can also provide an alternative payload to return instead of the pattern itself. This allows pattern based retrieval of objects. If no payload is provided the pattern itself will be returned.
instance.remove(pattern [,payload])
Removes a pattern from the Bloomrun instance. Filters are rebuilt after each removal which may mean the same pattern is matched by another filter. In cases where two patterns differ only by payload, the supplied payload can be used to determine the correct match. If no payload is supplied any matched pattern will be removed regardless of it's own payload.
instance.lookup(obj [, opts])
Looks up the first entry that matches the given obj. A match happens when all properties of the added pattern matches with the one in the passed obj. If a payload was provided it will be returned instead of the pattern.
Options:
patterns: true, if you want to retrieve only patterns, not payloads
instance.iterator(obj [, opts])
Returns an iterator, which is an object with a next method. next
will return the next pattern that matches the object or null if there
are no more.
If obj is null, all patterns/payload will be returned.
Options:
patterns: true, if you want to retrieve only patterns, not payloads
instance.list(obj [, opts])
Returns all patterns that matches the object. If a payload was provided
this will be returned instead of the pattern.
If obj is null, all patterns/payload will be returned.
Options:
patterns: true, if you want to retrieve only patterns, not payloads
Acknowledgements
This library is heavily inspired by Richard Rodger's patrun and seneca. Also, It would not be possible without bloomfilter.
The bloomrun logo was created, with thanks, by Dean McDonnell
License
Copyright Matteo Collina 2015-2016, Licensed under MIT.
