trie-completer

0.0.3 • Public • Published

A ternary search trie modified to support autocompletion suggestions.

It's kind of like a binary search tree with lexical ordering. Best case O(log n) lookups, and space requirements not significantly greater than the array of completions itself.

Construct with an array of strings:

const Completer = require('trie-completer');

let completer = new Completer([
    'a', 'aa', 'aaab', 'abc', 'def'
]);

Then you can get the completions for a prefix via completer.getCompletions(prefix) Completions will be sorted in ascending lexical order.

See Sedgewick & Wayne, Algorithms, 4th edition, Section 5.2

Package Sidebar

Install

npm i trie-completer

Weekly Downloads

0

Version

0.0.3

License

MIT

Last publish

Collaborators

  • imipolexg