A typescript implementation of the Prefix Trie data structure.
npm i js-trie --save
const { Trie } = require('js-trie');
let trie = new Trie();
trie.insert("apple");
trie.search("apple"); // returns true
trie.search("app"); // returns false
trie.startsWith("app"); // returns true
trie.insert("app");
trie.search("app"); // returns true
The library exposes the following functions:
- insert(word : string) : void
Inserts a word
into the prefix trie.
- search(word : string) : boolean
Returns true
if the word
exists in the prefix trie, otherwise false
.
- startsWith(prefix : string) : boolean
Returns true
if there exists a word that starts with part
, otherwise false
.