Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

persistent-hash-trie

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

persistent-hash-trie

Pure string:val storage, using structural sharing

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

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

mutable

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

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

keys

Returns an array of all keys in the trie

var trie = p.assoc(p.Trie(), 'key', 'val')
p.keys(trie) //= ['key']

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.

Keywords

FAQs

Package last updated on 29 Mar 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc