1.0.2 • Published 2 years ago

simple-trie-search v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

A simple trie implementation.

import Trie from "simple-trie-search";
// OR
const Trie = require("simple-trie-search");

// Instantiate a Trie object
const trie = new Trie()

// Add words by passing in a String, or by passing an Array.
trie.add("hello");
trie.search("h");
// [ 'Hello' ]

trie.add("help");
trie.search("he");
// [ 'help', 'hello' ]

trie.add(["a", "list", "of", "words"]);

// Values can be mapped to keys as well.
// Map values can be of any type.
trie.map("keyword", "value");
trie.search("key");
// [ 'value' ]

trie.map("hello", { world: "world", there: "there" });
trie.search("hello");
// [{ world: 'world', there: 'there' }]

// To delete a value, pass that value as an argument to the delete method.
trie.add("hello");
trie.delete("hello");
trie.search("hello");
// [ ]

// To delete a node and its children, pass its key as an argument to the deleteNode method.
trie.add(["meat", "me", "mean", "mat"]);
trie.deleteNode("me");
// [ 'mat' ]
1.0.2

2 years ago

1.0.1

3 years ago

1.0.0

3 years ago