JSPM

  • Created
  • Published
  • Downloads 38
  • Score
    100M100P100Q94363F
  • License MIT

React Hooks for using a Trie data structure

Package Exports

  • @cshooks/usetrie

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@cshooks/usetrie) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@cshooks/useTrie

A React Hook that returns a Trie, which enables a fast text match with a small memory foot print

Usage

import useTrie from "@cshooks/usetrie";

function App() {
  const words = ["abcd", "abce", "ABC", "THE", "their", "there"];
  const isCaseSensitive = false;
  const trie = useTrie(words, isCaseSensitive);

  return <div>...</div>;
}

Demo

Edit @cshooks/usetrie demo

API

  • has = (word: string, exactSearch: boolean = true): boolean
    • what? check if the word exists
    • word - a word to search in trie
    • exactSearch - match the word exactly else does a fuzzy match
  • add = (word: string): void
    • add the word to trie
  • remove = (word: string): void
    • remove the word from trie
  • isEmpty = (root: TrieNode = this.root): boolean
    • check if the current trie is empty or not.
    • optionally check if current trie node is empty or not