pub struct Dict<D> { /* private fields */ }Expand description
Read-only two-level dictionary over a byte container.
Implementations§
Source§impl<D: AsRef<[u8]>> Dict<D>
impl<D: AsRef<[u8]>> Dict<D>
pub fn new(data: D) -> Result<Self, FsaError>
pub fn is_empty(&self) -> bool
Sourcepub fn get(&self, code: &[u8]) -> Vec<(Vec<u8>, u64)>
pub fn get(&self, code: &[u8]) -> Vec<(Vec<u8>, u64)>
Items for an exact code, in stored (value-desc) order. Empty if the
code is absent. Allocates a Vec; hot paths should prefer the
allocation-free get_for_each.
Sourcepub fn get_for_each<F: FnMut(&[u8], u64)>(&self, code: &[u8], visit: F)
pub fn get_for_each<F: FnMut(&[u8], u64)>(&self, code: &[u8], visit: F)
Streaming variant of get: invoke visit(item, value)
for each item of an exact code with no result allocation and no
per-item copy (the item slice is valid only for the call). This is
the per-keystroke entry the IME dict layer should use.
Sourcepub fn contains_prefix(&self, prefix: &[u8]) -> bool
pub fn contains_prefix(&self, prefix: &[u8]) -> bool
true if any code starts with prefix.
Sourcepub fn prefix(&self, prefix: &[u8]) -> Vec<(Vec<u8>, Vec<u8>, u64)>
pub fn prefix(&self, prefix: &[u8]) -> Vec<(Vec<u8>, Vec<u8>, u64)>
All (code, item, value) triples whose code starts with prefix,
codes in sorted order, items in stored order within each code.
Sourcepub fn prefix_for_each<F: FnMut(&[u8], &[u8], u64)>(
&self,
prefix: &[u8],
visit: F,
)
pub fn prefix_for_each<F: FnMut(&[u8], &[u8], u64)>( &self, prefix: &[u8], visit: F, )
Streaming variant of prefix: invoke visit(code, item, value) per item without materializing the result — the hot
path (a bare-letter code prefix can match tens of thousands of items).
The code and item slices are valid only for the call.