#trie #binding #clone #darts #search #double-array-trie #double-a-rray

darts-clone-rs

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

3 releases

0.1.2 Sep 28, 2024
0.1.1 Sep 28, 2024
0.1.0 Sep 28, 2024

#1 in #darts

BSD-3-Clause

50KB
893 lines

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));
...
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);
}
...

Dependencies

~0.4–345KB