A trie dictionary storage model for Node.js
JavaScript
Latest commit f98bdac Jul 18, 2011 @kbjr fixed error in readme samples
Permalink
Failed to load latest commit information.
license.txt first commit Jun 27, 2011
package.json first commit Jun 27, 2011
readme.textile fixed error in readme samples Jul 18, 2011
trie.js first commit Jun 27, 2011

readme.textile

node-trie

Author: James Brumond
Version: 0.2.1

Copyright 2011 James Brumond
Dual licensed under MIT and GPL

Install

npm install trie

Samples

var trie = require('trie');

var myTrie = new trie.Trie();

// Adding words
myTrie.addWord('hello');
myTrie.addWord('world');

// Removing words
myTrie.removeWord('world');

// Checking for words
myTrie.lookup('hello'); // true
myTrie.lookup('world'); // false

// Testing prefixes
myTrie.isValidPrefix('h'); // true
myTrie.isValidPrefix('he'); // true
myTrie.isValidPrefix('ho'); // false

// Serializing
var jsonBlob = myTrie.dumpJson();

// Unserializing
var otherTrie = new trie.Trie();
otherTrie.loadJson(jsonBlob);

// Shortcut functions
var trie3 = trie.createTrieFromArray([ 'word1', 'word2', 'word3' ])
var trie4 = trie.createTrieFromJson(jsonBlob);