Skip to content

Javascript implementation of a Trie with customizable delimiters

License

Notifications You must be signed in to change notification settings

ejlangev/trie-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

trie-js

Javascript implementation of a Trie with customizable delimiters designed for use with the node environment.

Build Status

Installing

npm install trie-js

Creating a trie

// empty Trie with default delimiter
const trie = new Trie();

// trie with some initial values
const trie = new Trie(['abc', 'def']);

// trie with some initial values that are also iterable
const trie = new Trie([['a', 'b', 'c'], ['a', 'b', 'd']]);

// trie with custom object implementing iterator
const obj1 = {
  [Symbol.iterator]: function*() {
    yield 'a';
    yield 'b';
    yield 'd'
  }
}

const trie = new Trie([obj1]);

Adding, removing, and testing for values

const trie = new Trie();

// Adding is chainable
trie.add('abc')
  .add('def')
  .add('ghi');

// Removing is chainable
trie.remove('abc')
  .remove('def');

trie.lookup('abc') // false
trie.lookup('ghi') // true

Checking for prefixes

const trie = new Trie(['abc', 'def']);

trie.isPrefix('ab') // true
trie.isPrefix('abc') // false

About

Javascript implementation of a Trie with customizable delimiters

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published