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.
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.
npm install
npm run test
Kanwei's ruby code for Trie implementation.