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

ternary-search-trie

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ternary-search-trie

A ternary search tree implementation in TypeScript.

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Ternary Search Trie

A ternary search trie implementation in TypeScript.

Installing

You can install the package via npm or yarn.

NPM
npm install ternary-search-trie
Yarn
yarn add ternary-search-trie

End with an example of getting some data out of the system or using it for a little demo

Documentation

Trie

Represents a ternary search trie.

Usage
import { Trie } from 'ternary-search-trie';

interface ValueType {
  data: string;
}

const trie = new Trie<ValueType>();

Members

Trie.size

Gets the size of the tree in terms of the number of nodes present within the tree.

Methods

keys()

Gets all keys present in the tree.

set(key, value)

Creates a new node in the tree with the specified key and value.

ParamTypeDescription
keystringThe key of the node
valueValueTypeThe value of the node
get(key)

Recursively searches the tree for the node with the specified key and returns its value if it exists.

ParamTypeDescription
keystringThe key of the node
del(key)

Deletes a node from the tree if it exists.

ParamTypeDescription
keystringThe key of the node to delete
traverse(callback)

Performs a depth-first traversal of the tree starting from the root node.

ParamTypeDescription
callback(node: TrieNode) => voidThe callback to execute at each visited node
searchByPrefix(prefix, callback)

Searches the tree using the specified prefix.

ParamTypeDescription
prefixstringThe prefix to search by
callback(prefix: string, node: TrieNode) => voidThe callback to execute at each visited node
toString(options)
ParamTypeDescription
optionsobjectOptional parameters for printing the tree
options.showFunctionsbooleanDetermines whether or not functions in the tree should be displayed.
options.showValuesbooleanDetermines whether or not values in the tree should be displayed.
options.skipKeysstring[]Keys in the tree that should not be displayed.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

License

This project is licensed under the MIT License - see the LICENSE file for details

Acknowledgments

  • This project was heavily inspired by work done by @jakwings on node-ternary-search-trie. This project differs in that it is written in TypeScript and chose to implement the underlying functionality of the tree by making heavy use of recursion instead of loops.
  • Also the printing functionality of the tree is a replica of treeify from @notatestuser, but implemented in TypeScript.

Keywords

FAQs

Package last updated on 02 Oct 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