persistent-hash-trie
Pure string:val storage, using structural sharing
Last updated 12 years ago by hughfdjackson .
BSD · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install persistent-hash-trie 
SYNC missed versions from official npm registry.

persistent-hash-trie

Pure string:val storage, using structural sharing.

browser support

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 = require('persistent-hash-trie')

var trie = p.Trie()

assoc

Returns a new Trie with the new key:value keys added.

var trie1 = p.Trie()
var trie2 = p.assoc(trie1, 'key', { value: true })

dissoc

Returns a new Trie without a specific key

var trie1 = p.assoc(p.Trie(), 'key', 'val')
var trie2 = p.dissoc(trie2, 'key')

get

Retrieves a value from a Trie.

var trie = p.assoc(p.Trie(), 'key', 'val')
p.get(trie, 'key') //= 'val'

has

Returns true or false, depending on whether the value is in the Trie.

var trie = p.assoc(p.Trie(), 'key', 'val')
p.has(trie, 'key') 		//= true
p.has(trie, 'not-in-here') //= false

transient

Returns a mutable copy of a Trie, in the form of a js object.

var trie = p.assoc(p.Trie(), 'key', 'val')
p.transient(trie) //= { key: 'val' }

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 im = require('persistent-hash-trie')

var opts = {
	eq: function(a, b){ return a === b},
	hash: function(key){ return parseInt(key, 10) }
}

var vector = p.assoc(p.Trie(), 3, 'my-val', opts)
var val = p.get(vector, 3, opts)
var vector2 = p.dissoc(vector, 3, opts)
p.has(vector2, 3, opts) // false

Running tests and benchmarks

npm test and npm run-script benchmark are your friends.

Current Tags

  • 0.4.2                                ...           latest (12 years ago)

8 Versions

  • 0.4.2                                ...           12 years ago
  • 0.4.1                                ...           13 years ago
  • 0.4.0                                ...           13 years ago
  • 0.3.2                                ...           13 years ago
  • 0.3.1                                ...           13 years ago
  • 0.3.0                                ...           13 years ago
  • 0.2.4                                ...           13 years ago
  • 0.2.3                                ...           13 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (8)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |