Crates.io | pruning_radix_trie |
lib.rs | pruning_radix_trie |
version | 1.0.1 |
source | src |
created_at | 2022-09-05 23:09:55.508551 |
updated_at | 2024-09-15 11:01:54.854991 |
description | Rust implementation of Pruning Radix Trie, originally by Wolf Garbe |
homepage | https://github.com/peterall/pruning_radix_trie.git |
repository | https://github.com/peterall/pruning_radix_trie.git |
max_upload_size | |
id | 659162 |
size | 33,012 |
Rust implementation of Pruning Radix Trie, originally by Wolf Garbe (see credits/PruningRadixTrieLicense.txt).
Add terms with payloads to the trie with:
pub fn add(&mut self, term: &str, payload: T, weight: U);
After which you can prefix match with:
pub fn find(&self, prefix: &str, top_k: usize)
-> Vec<Result<T,U>>
Results are returned in descending order based on weight.
use pruning_radix_trie::PruningRadixTrie;
fn main() {
let mut trie = PruningRadixTrie::new();
trie.add("heyo", vec![1, 2, 3], 5);
trie.add("hello", vec![4, 5, 6], 10);
trie.add("hej", vec![7, 8, 9], 20);
let results = trie.find("he", 10);
for Result { term, payload, weight } in results {
println!("{:10}{:?}{:>4}", term, payload, weight);
}
//hej [7, 8, 9] 20
//hello [4, 5, 6] 10
//heyo [1, 2, 3] 5
}
N.B.: At the moment, the nightly channel of Rust is required.
First of all, install grcov
cargo install grcov
Second, install the llvm-tools Rust component (llvm-tools-preview
for now, it might become llvm-tools
soon):
rustup component add llvm-tools-preview
To run tests with code coverage run
bash run_source_cov.sh
A html coverage report will be generated in ./target/debug/coverage/
See rust-code-coverage-sample for details.