PTrie is a generic implementation of the trie data structure with no dependencies, tailored for easy and efficient prefix and postfix search within a collection of objects, such as strings.
The structure is defined as Trie<K, V>, where K represents the type of keys in each node (an iterator of the chain to index), and V is the type of the associated values (any object to which the key points to).
💭 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
Results are sorted in ascending order of their length.
✨ Find prefixes
You can return all prefixes in the trie that matches a given string, or directly retrieve 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 postfixes in the trie, e.g. all strings which have the given string as a prefix, and extends it.
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, to retrieve the associated value, or iterate the trie nodes.
use Trie;
let mut trie = new;
trie.insert;
trie.insert;
assert!;
assert!;
assert_eq!;
assert_eq!;
for in trie.iter
🏷️ Features
The serde feature adds Serde Serialize and Deserialize traits to the Trie and TrieNode struct.
= { = "0.6", = ["serde"] }
🛠️ Contributing
Contributions are welcome, checkout the CONTRIBUTING.md for instructions to run the project in development.
📜 Changelog
Changelog available in the CHANGELOG.md.