Skip to content

selvan/trie.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Trie based prefix tree to support fast auto-completion

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published