prefix-tree
Simple prefix-tree
Class to work with prefix tree. API is similiar to native Map.
Installation
npm install --save prefix-tree
Usage
var Tree = ; var tree = 'hi' 42 'hello' 'world' 'xo' 'xo'; tree;// → [ 42, 'world'] tree;tree;// → [ 'xo', { '42': 42 }]
API
prefixTree(items)
Parameter | Type | Description |
---|---|---|
items |
array |
optional Array of key-value pairs |
Example:
var tree = 'key' 'value' 'key2' 'value2' ;var tree2 = ;
set(key, value)
Parameter | Type | Description |
---|---|---|
key |
string |
key to search prefix in |
value |
any |
Anything you want to store |
Add value to prefix tree.
Example:
var tree = ;tree;
get(prefix)
Parameter | Type | Description |
---|---|---|
prefix |
string |
prefix to search values |
Get values for a prefix.
Example:
var tree = ; tree ; ; tree;// → [666, 'world']
toString()
For debug purpose you could use toString() method.
NB For perfomance module load inspection only with NODE_ENV === 'development'
NODE_ENV='development' node -e "console.log('' + new (require('prefix-tree'))([['hello', 'hello'], ['hi', 'hi'], ['hell', 'hell']]))" [root]└── h ├── e │ └── l │ └── l : hell │ └── o : hello └── i : hi
License
Code released under the MIT.