Expand description
Efficiently-updatable double-array trie in Rust (ported from cedar).
Add it to your Cargo.toml:
[dependencies]
cedarwood = "0.6"then you are good to go.
§Example
use cedarwood::Cedar;
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);Structs§
- Cedar
Cedarholds all of the information about double array trie.- Cedar
Builder - Configuration used to create a
Cedartrie. - Entries
- Iterator over every stored byte key and value.
- Memory
Stats - A snapshot of the trie’s owned-memory and occupancy metrics.
- Prefix
Iter - Iterator for
common_prefix_search - Prefix
Predict Iter - Iterator for
common_prefix_predict - Utf8
Entries - UTF-8 adapter for
Entries. Invalid byte keys are returned asFromUtf8Errorvalues.
Enums§
- Cedar
Error - Errors returned when configuring or mutating a trie.
- Cedar
Persistence Error - Errors returned while saving or loading cedarwood’s versioned binary format.
Constants§
- DEFAULT_
LOAD_ MEMORY_ LIMIT - Default ceiling for peak memory allocated while loading an untrusted serialized trie (512 MiB).
- MAX_
VALUE - The largest value accepted by
Cedar::update. - MIN_
VALUE - The smallest value accepted by
Cedar::update.