digital tree
Trie data structure implementation
Install
npm install --save digital-tree
API
var Trie = require('digital-tree')
var trie = new Trie()
put(key, value)
Put something in the tree
trie.put(['a', 'path', 'to'], 'something')
remove(key)
Remove something from the tree
given:
{ "a": {
"path": {
"to": {
"$": "value"
}
}
}
}
var subtree = trie.remove(['a', 'path'])
subtree will be:
{ "to": { "$": "value" } }
Trie underlying data will look like this after the removal:
{ "a": {}}
get(key)
Get something from the tree
var value = trie.get(['a', 'path', 'to'])
value will be the string "something"
searchByPrefix(key, excludeEmptyKeys)
Search for all the entries under key
var result = trie.searchByPrefix(['a', 'path'])
result will be:
[ [ [ "a", "path", "to" ], "something" ] ]
TODO
- add benchmarks of other similar modules