0.0.10 • Published 2 years ago

@joenano/trie v0.0.10

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Trie

A Trie data structure for strings in JS

Install

npm i @joenano/trie

Import

const Trie = require('@joenano/trie');

Insert

const trie = new Trie();

var strings = ['string 1', 'string 2', 'string 3'];

for(string of strings) {
    trie.insert(string);
}

Contains

Check if string exists in trie. Returns false for substrings.

if(trie.contains('string 1')) {
    console.log('string found');
}

Find

Returns array of strings with a given prefix.

let found = trie.find('str');

// found = ['string 1', 'string 2', 'string 3']

Remove

trie.remove('string 1');

let found = trie.find('str');

// found = ['string 2', 'string 3']

Caching

Array results of find are cached by default, you can disbale this by setting caching to false.

trie.caching = false;

The cache is cleared automatically if a string is removed from the trie, but if you insert after the initial build you will have to manually clear the cache.

trie.insert('new string');
trie.clearCache();

String count

console.log('Strings in trie: ', trie.stringCount);
0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago