Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Latest commit

 

History

History
44 lines (30 loc) · 866 Bytes

readme.textile

File metadata and controls

44 lines (30 loc) · 866 Bytes

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);