persistent-hash-trie
Advanced tools
Comparing version 0.3.0 to 0.3.1
'use strict' | ||
var _ = require('lodash') | ||
var gen = require('./gen-data') | ||
var gen = require('./gen-keys') | ||
var versions = require('./versions') | ||
@@ -9,3 +9,3 @@ | ||
var suite = new require('benchmark').Suite('assoc property with Trie of ' + quantity) | ||
var data = gen(quantity, Math.random()) | ||
var keys = gen.words(quantity) | ||
@@ -16,4 +16,4 @@ var test = function(o){ | ||
var trie = _.reduce(data, function(trie, val, key){ | ||
return p.assoc(trie, key, val) | ||
var trie = _.reduce(keys, function(trie, key){ | ||
return p.assoc(trie, key, true) | ||
}, p.Trie()) | ||
@@ -20,0 +20,0 @@ |
'use strict' | ||
var _ = require('lodash') | ||
var gen = require('./gen-data') | ||
var gen = require('./gen-keys') | ||
var versions = require('./versions') | ||
@@ -9,3 +9,3 @@ | ||
var suite = new require('benchmark').Suite('dissoc property with Trie of ' + quantity) | ||
var data = gen(quantity, Math.random()) | ||
var keys = gen.words(quantity) | ||
@@ -16,5 +16,6 @@ var test = function(o){ | ||
var trie = _.reduce(data, function(trie, val, key){ | ||
return p.assoc(trie, key, val) | ||
var trie = _.reduce(keys, function(trie, key){ | ||
return p.assoc(trie, key, true) | ||
}, p.Trie()) | ||
trie = p.assoc(trie, 'key', 'val') | ||
@@ -21,0 +22,0 @@ |
'use strict' | ||
var _ = require('lodash') | ||
var gen = require('./gen-data') | ||
var gen = require('./gen-keys') | ||
var versions = require('./versions') | ||
@@ -9,3 +9,3 @@ | ||
var suite = new require('benchmark').Suite('get property with Trie of ' + quantity) | ||
var data = gen(quantity, Math.random()) | ||
var keys = gen.words(quantity, Math.random()) | ||
@@ -16,4 +16,4 @@ var test = function(o){ | ||
var trie = _.reduce(data, function(trie, val, key){ | ||
return p.assoc(trie, key, val) | ||
var trie = _.reduce(keys, function(trie, key){ | ||
return p.assoc(trie, key, true) | ||
}, p.Trie()) | ||
@@ -20,0 +20,0 @@ trie = p.assoc(trie, 'key', 'val') |
'use strict' | ||
var _ = require('lodash') | ||
var gen = require('./gen-data') | ||
var gen = require('./gen-keys') | ||
var versions = require('./versions') | ||
@@ -9,3 +9,3 @@ | ||
var suite = new require('benchmark').Suite('has property with Trie of ' + quantity) | ||
var data = gen(quantity, Math.random()) | ||
var keys = gen.words(quantity) | ||
@@ -16,4 +16,4 @@ var test = function(o){ | ||
var trie = _.reduce(data, function(trie, val, key){ | ||
return p.assoc(trie, key, val) | ||
var trie = _.reduce(keys, function(trie, key){ | ||
return p.assoc(trie, key, true) | ||
}, p.Trie()) | ||
@@ -20,0 +20,0 @@ trie = p.assoc(trie, 'key', 'val') |
'use strict' | ||
var _ = require('lodash') | ||
var gen = require('./gen-data') | ||
var gen = require('./gen-keys') | ||
var versions = require('./versions') | ||
@@ -9,3 +9,3 @@ | ||
var suite = new require('benchmark').Suite('keys of Trie with ' + quantity + ' members') | ||
var data = gen(quantity, Math.random()) | ||
var keys = gen.words(quantity) | ||
@@ -16,4 +16,4 @@ var test = function(o){ | ||
var trie = _.reduce(data, function(trie, val, key){ | ||
return p.assoc(trie, key, val) | ||
var trie = _.reduce(keys, function(trie, key){ | ||
return p.assoc(trie, key, true) | ||
}, p.Trie()) | ||
@@ -20,0 +20,0 @@ |
'use strict' | ||
var _ = require('lodash') | ||
var gen = require('./gen-data') | ||
var gen = require('./gen-keys') | ||
var versions = require('./versions') | ||
@@ -9,3 +9,3 @@ | ||
var suite = new require('benchmark').Suite('mutable version of Trie with ' + quantity + ' members') | ||
var data = gen(quantity, Math.random()) | ||
var keys = gen.words(quantity) | ||
@@ -17,4 +17,4 @@ var test = function(o){ | ||
var trie = _.reduce(data, function(trie, val, key){ | ||
return p.assoc(trie, key, val) | ||
var trie = _.reduce(keys, function(trie, key){ | ||
return p.assoc(trie, key, true) | ||
}, p.Trie()) | ||
@@ -21,0 +21,0 @@ |
@@ -12,3 +12,3 @@ 'use strict' | ||
this.map(function(results){ | ||
log(results.name + ' : ' + results.count + ' ± ' + results.stats.rme + '%') | ||
log(results.name + ' : ' + results.count + ' ± ' + results.stats.rme + '% ops/sec') | ||
}) | ||
@@ -15,0 +15,0 @@ } |
module.exports = [ | ||
{ name: 'current', module: require('..') }, | ||
{ name: 'v0.2.3', module: require('./previous-versions/0.2.3/') }, | ||
{ name: 'v0.2.4', module: require('./previous-versions/0.2.4/') }, | ||
{ name: 'v0.3.0', module: require('./previous-versions/0.3.0/') } | ||
{ name: 'shallow-copy reference ', module: require('./reference-versions/shallow-copy.js') }, | ||
{ name: 'current ', module: require('..') }, | ||
{ name: 'v0.2.3 ', module: require('./previous-versions/0.2.3/') }, | ||
{ name: 'v0.2.4 ', module: require('./previous-versions/0.2.4/') }, | ||
{ name: 'v0.3.0 ', module: require('./previous-versions/0.3.0/') } | ||
] |
@@ -5,3 +5,3 @@ | ||
"description": "Pure string:val storage, using structural sharing", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"main": "src/persistent-hash-trie.js", | ||
@@ -8,0 +8,0 @@ "scripts": { |
@@ -51,3 +51,2 @@ 'use strict' | ||
// hash function for strings, based on Java's String.hashCode: | ||
@@ -59,6 +58,7 @@ // http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#hashCode() | ||
for ( var i = 0; i < l; i += 1 ) | ||
h += str.charCodeAt(i) * 31 * l - i | ||
h = h * 31 + str.charCodeAt(i) | ||
return h | ||
} | ||
// to allow hooks for other implementations/tests to override the default | ||
@@ -99,59 +99,2 @@ // hash and equality functions (which are the necessary ones for creating | ||
// Node, String, (Int), (Object)-> Bool | ||
// Trie-equivalent of the 'in' operator. | ||
// Has recurses down a node, using hashMask to navigate a 'path' down branches. | ||
// If a value node is found, if its key is equal to the key provided, then the | ||
// Trie contains the key, and true is returned. | ||
// Hashmaps store values in the outermost leaves when necessary. If they contain | ||
// a key, it also means that the key is in the trie,. | ||
var has = function(trie, key, opts, depth){ | ||
return hasFns[trie.type](trie, key, opts || defaultOpts, depth || 0) | ||
} | ||
var hasFns = { | ||
trie: function(node, key, opts, depth){ | ||
var child = node.children[hashMask(key, depth, opts.hash)] | ||
if ( child === undefined ) return false | ||
else return has(child, key, opts, depth + 1) | ||
}, | ||
value: function(node, key, opts){ | ||
return opts.eq(node.key, key) | ||
}, | ||
hashmap: function(node, key, opts){ | ||
return key in node.values | ||
} | ||
} | ||
// Node, String, (Int), (Object) -> Value | ||
// Trie-equivalent of dot or bracket syntax - retrieves a value assocaited with a key | ||
// or undefined. | ||
// get recurses down the Trie, similarly to has. If it finds a matching key, instead | ||
// of returning true or false, however, it unpacks the value associated with the key | ||
// and returns that instead. | ||
var get = function(trie, key, opts, depth){ | ||
return getFns[trie.type](trie, key, opts || defaultOpts, depth || 0) | ||
} | ||
var getFns = { | ||
trie: function(node, key, opts, depth){ | ||
var child = node.children[hashMask(key, depth, opts.hash)] | ||
if ( child === undefined ) return undefined | ||
else return get(child, key, opts, depth + 1) | ||
}, | ||
value: function(node, key, opts, depth){ | ||
if ( opts.eq(node.key, key) ) return node.value | ||
}, | ||
hashmap: function(node, key, opts, depth){ | ||
var value = node.values[key] | ||
return value ? value.value : undefined | ||
} | ||
} | ||
// Object, String, JSValue -> Object | ||
@@ -320,2 +263,61 @@ | ||
// Node, String, (Int), (Object)-> Bool | ||
// Trie-equivalent of the 'in' operator. | ||
// Has recurses down a node, using hashMask to navigate a 'path' down branches. | ||
// If a value node is found, if its key is equal to the key provided, then the | ||
// Trie contains the key, and true is returned. | ||
// Hashmaps store values in the outermost leaves when necessary. If they contain | ||
// a key, it also means that the key is in the trie,. | ||
var has = function(trie, key, opts, depth){ | ||
return hasFns[trie.type](trie, key, opts || defaultOpts, depth || 0) | ||
} | ||
var hasFns = { | ||
trie: function(node, key, opts, depth){ | ||
var child = node.children[hashMask(key, depth, opts.hash)] | ||
if ( child === undefined ) return false | ||
else return has(child, key, opts, depth + 1) | ||
}, | ||
value: function(node, key, opts){ | ||
return opts.eq(node.key, key) | ||
}, | ||
hashmap: function(node, key, opts){ | ||
return key in node.values | ||
} | ||
} | ||
// Node, String, (Int), (Object) -> Value | ||
// Trie-equivalent of dot or bracket syntax - retrieves a value assocaited with a key | ||
// or undefined. | ||
// get recurses down the Trie, similarly to has. If it finds a matching key, instead | ||
// of returning true or false, however, it unpacks the value associated with the key | ||
// and returns that instead. | ||
var get = function(trie, key, opts, depth){ | ||
return getFns[trie.type](trie, key, opts || defaultOpts, depth || 0) | ||
} | ||
var getFns = { | ||
trie: function(node, key, opts, depth){ | ||
var child = node.children[hashMask(key, depth, opts.hash)] | ||
if ( child === undefined ) return undefined | ||
else return get(child, key, opts, depth + 1) | ||
}, | ||
value: function(node, key, opts, depth){ | ||
if ( opts.eq(node.key, key) ) return node.value | ||
}, | ||
hashmap: function(node, key, opts, depth){ | ||
var value = node.values[key] | ||
return value ? value.value : undefined | ||
} | ||
} | ||
// Node -> Object | ||
@@ -340,3 +342,3 @@ | ||
trie: function(node, curr){ | ||
for ( var key in node.children ) mutable(node.children[key], curr) | ||
for ( var path in node.children ) mutable(node.children[path], curr) | ||
}, | ||
@@ -363,3 +365,3 @@ value: function(node, curr){ | ||
trie: function(node, arr){ | ||
for ( var key in node.children ) keys(node.children[key], arr) | ||
for ( var path in node.children ) keys(node.children[path], arr) | ||
}, | ||
@@ -366,0 +368,0 @@ value: function(node, arr){ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
386019
255
8539
67
0