Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-ternary-search-trie

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

node-ternary-search-trie

A simple class for ternary search trie in Node.js™.

  • 5.5.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
Maintainers
1
Weekly downloads
 
Created
Source

A simple class for ternary search trie implemented in JavaScript.

Build Status NPM version

It is unstable and not for production use. ;)

You can install it via npm install node-ternary-search-trie, or just include the script lib/trie.js in your web pages.

var Trie = Trie || require('node-ternary-search-trie');

var trie = new Trie();

Public methods (with simple Unicode support):

  • set(key, value) -> this

    Insert one key-value pair into the trie. This will overwrite the existed key-value pair. value should not be null or undefined.

  • get(key, toSplay = false) -> value:

    Fetch the stored value of the given key.

    get and set methods may be greatly affected after each splaying operation. Splay with caution.

  • del(key) -> this

    Delete the key-value pair for the given key.

  • size() -> size

    Return the total number of nodes in the trie.

  • keys() -> [keys...]

    Sort and return all keys stored in the trie.

  • keysWithPrefix(prefix) -> [keys...]

    Sort and return all keys started with the given prefix.

  • keysWithCommonPrefix(key) -> [keys...]

    Sort and return all keys that are prefixes of the given key.

  • keysWithinHammingDistance(key, distance) -> [keys...]

    Sort and return all keys within a Hamming distance of the given key.

  • keysWithinLevenshteinDistance(key, distance) -> [keys...]

    Sort and return all keys within a Levenshtein distance of the given key.

  • keysWithinDamerauLevenshteinDistance(key, distance) -> [keys...]

    Sort and return all keys within a Damerau-Levenshtein distance of the given key.

  • searchWithPrefix(prefix, callback: (key, value) -> void) -> this

    Just like keysWithPrefix.

  • searchWithCommonPrefix(key, callback: (key, value) -> void) -> this

    Just like keysWithCommonPrefix.

  • searchWithinHammingDistance(key, distance, callback: (key, value, distance) -> void) -> this

    Just like keysWithinHammingDistance.

  • searchWithinLevenshteinDistance(key, distance, callback: (key, value, distance) -> void) -> this

    Just like keysWithinLevenshteinDistance.

  • searchWithinDamerauLevenshteinDistance(key, distance, callback: (key, value, distance) -> void) -> this

    Just like keysWithinDamerauLevenshteinDistance.

  • traverse(callback: (key, value) -> void) -> this

    Traverse in in-order. (sorted)

  • traversal() -> iterator

    Return an iterator for in-order traversal. iterator.next() will return {value: undefined | {key, value}, done: Boolean}.

Keywords

FAQs

Package last updated on 10 Sep 2019

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