Crates.io | pfx |
lib.rs | pfx |
version | 0.4.1 |
source | src |
created_at | 2024-04-02 18:24:47.736746 |
updated_at | 2024-04-07 08:21:51.713187 |
description | A prefix tree (map and set), implemented without any unsafe |
homepage | |
repository | https://github.com/H2CO3/pfx |
max_upload_size | |
id | 1193976 |
size | 61,522 |
This crate provides a prefix tree map and set data structure, implemented purely in safe Rust.
The API is very similar to std::collections::{HashMap, BTreeMap}
, including iteration and
an entry API. Iteration proceeds in lexicographical order as determined by the keys.
A notable addition is Prefix search, allowing iteration over all entries whose key starts with a specified prefix.
use pfx::PrefixTreeMap;
fn main() {
let mut map: PrefixTreeMap<String, u64> = PrefixTreeMap::new();
map.insert("abc".into(), 123);
map.insert("def".into(), 456);
map.insert("defghi".into(), 789);
assert_eq!(map.get("abc").copied(), Some(123));
assert_eq!(map.get("abcdef").copied(), None);
assert_eq!(map.get("ab").copied(), None);
for (key, value) in map.prefix_iter("de") {
println!("{key} => {value}");
}
}