NOTE
This project is no longer actively supported. If anyone is interested in becoming the new maintainer, don't hesitate to contact me (hughfdjackson@googlemail.com).
For an alternative, consider https://npmjs.org/package/mori.
persistent-hash-trie
Pure string:val storage, using structural sharing.
Why
This module forms a possible basis for effecient persistent datastructures; such as those found in Clojure's PersistentHashMap and PersistentVector.
Install
npm install persistent-hash-trie
Docs
Trie
var p = var trie = p
assoc
Returns a new Trie with the new key:value keys added.
var trie1 = pvar trie2 = p
dissoc
Returns a new Trie without a specific key
var trie1 = pvar trie2 = p
get
Retrieves a value from a Trie.
var trie = pp //= 'val'
has
Returns true
or false
, depending on whether the value is in the Trie.
var trie = pp //= truep //= false
mutable
Returns a mutable copy of a Trie, in the form of a js object.
var trie = pp //= { key: 'val' }
keys
Returns an array of all keys in the trie
var trie = pp //= ['key']
reduce
The traditional reduce - requires seed.
// definition of `mutable` using reduce: var { return p} var { okey = val return o}
Can be cancelled early:
var { return p}
Extending assoc/dissoc/get/has
The hashing and equality functions used on the keys can be overidden by passing an opts object to assoc
, dissoc
, get
and has
.
var p = var opts = { return a === b} { return } var vector = pvar val = pvar vector2 = pp // false
Running tests and benchmarks
npm test
and npm run benchmark
are your friends.