persistent-hash-trie

WebJar for persistent-hash-trie

Лицензия

Лицензия

BSD
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

persistent-hash-trie
Последняя версия

Последняя версия

0.4.2
Дата

Дата

Тип

Тип

jar
Описание

Описание

persistent-hash-trie
WebJar for persistent-hash-trie
Ссылка на сайт

Ссылка на сайт

http://webjars.org
Система контроля версий

Система контроля версий

https://github.com/hughfdjackson/persistent-hash-trie

Скачать persistent-hash-trie

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/persistent-hash-trie/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>persistent-hash-trie</artifactId>
    <version>0.4.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/persistent-hash-trie/
implementation 'org.webjars.npm:persistent-hash-trie:0.4.2'
// https://jarcasting.com/artifacts/org.webjars.npm/persistent-hash-trie/
implementation ("org.webjars.npm:persistent-hash-trie:0.4.2")
'org.webjars.npm:persistent-hash-trie:jar:0.4.2'
<dependency org="org.webjars.npm" name="persistent-hash-trie" rev="0.4.2">
  <artifact name="persistent-hash-trie" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='persistent-hash-trie', version='0.4.2')
)
libraryDependencies += "org.webjars.npm" % "persistent-hash-trie" % "0.4.2"
[org.webjars.npm/persistent-hash-trie "0.4.2"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
org.webjars.npm : string-hash jar 1.1.0

Модули Проекта

Данный проект не имеет модулей.

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.

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']

reduce

The traditional reduce - requires seed.

// definition of `mutable` using reduce:

var mutable = function(node){
    return p.reduce(node, addKeyVal, {})
}

var addKeyVal = function(o, val, key){
    o[key] = val
    return o
}

Can be cancelled early:

var some = function(node, predicate){
	return p.reduce(node, function(seed, value){
		if ( !predicate(value)) return p.reduce.Break(false)
		else                    return true
	}, true)
}

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 = 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 benchmark are your friends.

Версии библиотеки

Версия
0.4.2