A simple Trie data structure for optimized for lowercased latin alphanumeric strings. Optimization was done based on the following assumption:
- Lookup keys consists of alphabetical characters.
- Each Node in the trie holds an array of 36 cells for optimal lookup.
- 26 first cells are for lowercased alphabetical characters and the rest 10 for numeric.
- If a non supported character is inserted (e.g.
≈
,\
etc.), it is skipped.
Install via npm:
npm i trie-typescript
or via yarn:
yarn add trie-typescript
JS usage example:
import { AlphaNumericTrie } from "trie-typescript";
const alphaNumericTrie = new AlphaNumericTrie();
alphaNumericTrie.add("foo123", { myVal: "bar" });
alphaNumericTrie.has("foo123"); // true
alphaNumericTrie.get("foo123"); // {myVal: "bar"}
alphaNumericTrie.add("Foo!!!", { myVal: "!!!bar" });
alphaNumericTrie.has("Foo!!!"); // false
alphaNumericTrie.get("foo"); // {myVal: "!!!bar"}
Feel free to reach out for feedback.