PTrie is a versatile implementation of the trie data structure, tailored for efficient prefix searching within a collection of objects, such as strings, with no dependencies.
The structure is defined as Trie<K, V>, where K represents the type of keys in each node, and V is the type of the associated values.
💭 Motivation
The trie is particularly effective for operations involving common prefix identification and retrieval, making it a good choice for applications that require fast and efficient prefix-based search functionalities.
🚀 Usage
✨ Find prefixes
You can return all prefixes in the trie corresponding to a given string, sorted in ascending order of their length, or directly the longest prefix.
use Trie;
let mut trie = new;
trie.insert;
trie.insert;
trie.insert;
trie.insert;
let prefixes = trie.find_prefixes;
assert_eq!;
let longest = trie.find_longest_prefix;
assert_eq!;
🔍 Find postfixes
You can also find all strings in the trie that begin with a specified prefix.
use Trie;
let mut trie = new;
trie.insert;
trie.insert;
trie.insert;
trie.insert;
let strings = trie.find_postfixes;
assert_eq!;
🔑 Key-based Retrieval Functions
The crate provides functions to check for the existence of a key and to retrieve the associated value.
use Trie;
let mut trie = new;
trie.insert;
assert!;
assert!;
assert_eq!;
assert_eq!;
🏷️ Features
The serde feature adds Serde Serialize and Deserialize traits to the Trie and TrieNode struct.