Skip to content

Latest commit

 

History

History
34 lines (21 loc) · 1.16 KB

README.md

File metadata and controls

34 lines (21 loc) · 1.16 KB

trie.js

Ternary Search Tree - Trie based prefix tree implementation to support fast auto-completion.

trie.js shall be used as standalone library or shall be used with node.js.

Common usage

var _trie = new Trie();

_trie.push("Hello", {"id":1, "txt":"Hello World"});
_trie.push("Hilly", {"id":2, "txt":"Hello Hilly"});
_trie.push("Hello, brother", {"id":3, "txt":"Whats up?"});
_trie.push("Hello, bob", {"id":4, "txt":"Hey dude"});


Query 1:
_trie.wildcard("H*ll.", -1) /* -1 for retrieving all matches, positive integer for limit number of matches */
                            /* Notice support for * and . wildcards */
Return for Query 1:
{ key : 'Hello', values : {"id":1, "txt":"Hello World"} },
{ key : 'Hilly', values : {"id":2, "txt":"Hello Hilly"} }

See spec/trie_spec.js for more usage patterns.

Running specs

npm install
npm run test

Credit

Kanwei's ruby code for Trie implementation.