Quick Trie
Trie implementation for faster searches
Trie
A trie structure an efficient way to match strings. It's worst computational complexity is O(N) where N is the length of the key.
For this reason trie search is commonly used in routing algorithms on web servers.
Features
- Pattern matching in linear time
- Efficient String Searching
- Static Typing
Get Started
Install
yarn add quick-trie
Simple Usage
By default, key matching are case insensitive.
const root = init<number>();
add(root, 'foo', 1);
console.log(get(root, 'foo'));
console.log(get(root, 'FOO'));
To disable ignore casing, simply pass config
object to the init
function
const root = init<number>({
ignoreCasing: false,
});
add(root, 'foo', 1);
console.log(get(root, 'foo'));
console.log(get(root, 'FOO'));
Search String
const root = init<number>();
add(root, 'hello world', 1);
add(root, 'world class', 2);
console.log(search(root, 'world'));
[1, 2];
console.log(search(root, 'hello'));
[1];
console.log(search(root, 'class'));
[2];