New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dtrie

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dtrie

Trie implementation based on a minimal automaton.

  • 1.4.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Trie implementation based on a minimal automaton for Node.js Build Status

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

Installation

npm install dtrie

Tests

To run the unit tests:

npm test

To run the performance/stress tests:

npm run-script stress

Usage

Basic dictionary usage:

var dtrie = require('dtrie');

var trie = dtrie.createFromWords(['ai', 'aient', 'aime', 'aimer']);

assert.ok(trie.contains('ai'));
assert.ok(!trie.contains('aimerait'));

API

dtrie.loadFromFile(filepath)

  • filepath: path to dictionary (one word per line, unix eol)

Construct a dictionary from a file.

dtrie.createFromWords(words)

  • words: a list of lowercase words

Construct a dictionary from a list of words.

Class Node

new Node([id])
  • id: overwrite the generated id

Construct a new node.

node.id

Node's id, unique to each node.

node.letters

Node's transitions.

node.hasChild(letter)
  • letter: transition label

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

node.getChild(letter)
  • letter: transition label

Return the node child.

node.accepts(suffix)
  • suffix: a suffix to check

Check if this node recognize the given suffix.

node.isTerminal()

Return true if the current node is a terminal node.

Class Automaton

This class is a subclass of Node and represent an automaton.

new Automaton()

Construct a new automaton.

automaton.populate(words)
  • words: an alphabetically sorted list of lowercase words

Populate the automaton from an alphabetically sorted list of lowercase words. This method should only be called once per automaton. Words must contain letters within range [a-z].

automaton.contains(word)
  • word: the word to lookup

Return true if the automaton recognize the given word.

automaton.getSize()

Return the number of nodes in the automaton.

License

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

Keywords

FAQs

Package last updated on 13 Mar 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc