rust-cedar

Crates.iorust-cedar
lib.rsrust-cedar
version0.1.0
sourcesrc
created_at2019-07-10 16:15:30.767526
updated_at2019-07-10 16:15:30.767526
descriptionefficiently-updatable double-array trie in Rust (ported from cedar)
homepage
repositoryhttps://github.com/MnO2/rust-cedar
max_upload_size
id148105
size37,598
Paul Meng (MnO2)

documentation

README

rust-cedar

Efficiently-updatable double-array trie in Rust (ported from cedar). This library is still in alpha, feedbacks are welcomed.

Build Status codecov

Installation

Add it to your Cargo.toml:

[dependencies]
cedar = "0.1"

then you are good to go. If you are using Rust 2015 you have to extern crate darts to your crate root as well.

Example

let dict = vec![
    "a",
    "ab",
    "abc",
    "アルゴリズム",
    "データ",
    "構造",
    "网",
    "网球",
    "网球拍",
    "中",
    "中华",
    "中华人民",
    "中华人民共和国",
];
let key_values: Vec<(&str, i32)> = dict.into_iter().enumerate().map(|(k, s)| (s, k as i32)).collect();
let mut cedar = Cedar::new();
cedar.build(&key_values);

let result: Vec<i32> = cedar.common_prefix_search("abcdefg").iter().map(|x| x.0).collect();
assert_eq!(vec![0, 1, 2], result);

let result: Vec<i32> = cedar
    .common_prefix_search("网球拍卖会")
    .iter()
    .map(|x| x.0)
    .collect();
assert_eq!(vec![6, 7, 8], result);

let result: Vec<i32> = cedar
    .common_prefix_search("中华人民共和国")
    .iter()
    .map(|x| x.0)
    .collect();
assert_eq!(vec![9, 10, 11, 12], result);

let result: Vec<i32> = cedar
    .common_prefix_search("データ構造とアルゴリズム")
    .iter()
    .map(|x| x.0)
    .collect();
assert_eq!(vec![4], result);

To run benchmark tests

cargo bench 

License

This work is released under the BSD-2 license, following the original license of C++ cedar. A copy of the license is provided in the LICENSE file.

Reference

Commit count: 112

cargo fmt