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

kbjr/node-trie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A trie dictionary storage model for Node.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published