dtrie

Trie implementation based on a minimal automaton.

Node.js trie implementation based on a Minimal Acyclic Finite-State Automata

Node.js trie implementation based on a Minimal Acyclic Finite-State Automata.

Implementation based on "Incremental Construction of Minimal Acyclic Finite-State Automata" by Jan Daciuk, Stoyan Mihov, Bruce W. Watson and Richard E. Watson.

npm install dtrie
  • id: overwrite the generated id

Construct a new node.

Node's id, unique to each node.

Node's transitions.

  • letter: transition label

Return true if this node has a child for the given transition.

  • letter: transition label

Return the node child.

  • path: a word to follow

Check if a path exists from this node to a terminal node.

Return true if the current node is a terminal node.

This class is a subclass of Node.

Construct a new automata.

  • words: an alphabetically sorted list of lowercase words

Populate the automata from an alphabetically sorted list of lowercase words. This method should only be called once per automata.

  • word: the word to lookup

Return true if the automata recognize the given word.

Return the number of nodes in the automata.

This code is free to use under the terms of the MIT license.