darts-clone-rs

Crates.iodarts-clone-rs
lib.rsdarts-clone-rs
version0.1.2
sourcesrc
created_at2024-09-28 16:36:52.012648
updated_at2024-09-28 17:51:21.592628
descriptionRust binding of a clone of Darts (Double-ARray Trie System)
homepage
repositoryhttps://github.com/WhiredPlanck/darts-clone-rs
max_upload_size
id1390233
size27,459
WhiredPlanck (WhiredPlanck)

documentation

https://docs.rs/darts-clone-rs

README

darts-clone-rs

Rust binding of Darts-clone - a clone of Darts (Double-ARray Trie System)

Installation

[dependencies]
darts-clone-rs = "0.1.0"

Example

Build trie

use darts::DartsArrayTrie;
...
let dic = DartsArrayTrie::new();
let keys: Vec<String> = ... // get keys somehow
let values: Vec<usize> = ... // get values somehow
let lengths: Vec<i32> = ... // get lengths somehow

let result = dic.build(keys.len, &keys, None /* Some(&values) */, None /* Some(&lengths) */, None);
assert_eq!(Ok(()), result);
...

Save and open

use darts::DartsArrayTrie;
...
let dic = DartsArrayTrie::new();
// build ...
let dic_copy = DartsArrayTrie::new();
assert_eq!(Ok(), dic.save("path/to/dict", "wb", 0));
assert_eq!(Ok(), dic_copy.open("path/to/dict", "rb", 0, 0));
...

Search

use darts::DartsArrayTrie;
...
const MAX_RESULT_NUM: usize = 16;
let dic = DartsArrayTrie::new();
// build ...
let result = dic.common_prefix_search(key, MAX_RESULT_NUM, 0, 0);
assert_eq!(/* prefixes */, result);
...

Traverse

use darts::DartsArrayTrie;
...
let dic = DartsArrayTrie::new();
// build ...
let mut id = 0usize;
let mut key_pos = 0usize;
for i in 0..key.len() {
    let result = dic.traverse(key, &mut id, &mut key_pos, i + 1);
    assert_ne!(result, -2);
}
...
Commit count: 23

cargo fmt