pruning_radix_trie

Crates.iopruning_radix_trie
lib.rspruning_radix_trie
version1.0.1
sourcesrc
created_at2022-09-05 23:09:55.508551
updated_at2024-09-15 11:01:54.854991
descriptionRust implementation of Pruning Radix Trie, originally by Wolf Garbe
homepagehttps://github.com/peterall/pruning_radix_trie.git
repositoryhttps://github.com/peterall/pruning_radix_trie.git
max_upload_size
id659162
size33,012
Peter Allwin (peterall)

documentation

README

Pruning Radix Trie

Rust implementation of Pruning Radix Trie, originally by Wolf Garbe (see credits/PruningRadixTrieLicense.txt).

Usage

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.

Example

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
}

Testing

Measuring code coverage

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.

Commit count: 14

cargo fmt