pub struct TermDictionary { /* private fields */ }Expand description
A sorted, front-coded term dictionary.
Implementations§
Source§impl TermDictionary
impl TermDictionary
Sourcepub fn from_map(entries: &BTreeMap<Vec<u8>, TermInfo>) -> Self
pub fn from_map(entries: &BTreeMap<Vec<u8>, TermInfo>) -> Self
Builds a dictionary from an ordered map of terms.
A BTreeMap is required rather than accepted for convenience: it
makes the sorted precondition a type-level fact, so the ordering
cannot be violated by a caller iterating a hash map.
Sourcepub fn push(&mut self, term: &[u8], info: TermInfo) -> Result<(), DictError>
pub fn push(&mut self, term: &[u8], info: TermInfo) -> Result<(), DictError>
Appends one term. Terms must arrive sorted and unique.
§Errors
Returns DictError::NotSorted or DictError::Duplicate.
Sourcepub fn encoded_bytes(&self) -> &[u8] ⓘ
pub fn encoded_bytes(&self) -> &[u8] ⓘ
Returns the front-coded bytes.
Sourcepub fn info_at(&self, index: usize) -> Option<TermInfo>
pub fn info_at(&self, index: usize) -> Option<TermInfo>
Returns the information at a flat index.
Sourcepub fn seek_exact(&self, term: &[u8]) -> Option<usize>
pub fn seek_exact(&self, term: &[u8]) -> Option<usize>
Returns the flat index of term, if present.
Binary-searches the materialized block heads, then walks at most one block. This is the operation task 15’s automaton-guided seek repeats.
Sourcepub fn seek_ceiling(&self, term: &[u8]) -> Option<usize>
pub fn seek_ceiling(&self, term: &[u8]) -> Option<usize>
Returns the flat index of the first term at or after term.
This is the primitive task 15’s Levenshtein walk drives: from an automaton state it computes the smallest acceptable next term and seeks here, rather than enumerating the dictionary.
Sourcepub fn prefix_range(&self, prefix: &[u8]) -> Result<Range<usize>, DictError>
pub fn prefix_range(&self, prefix: &[u8]) -> Result<Range<usize>, DictError>
Returns every flat index whose term starts with prefix.
§Errors
Returns DictError::EmptyTerm for an empty prefix. An empty prefix
is a full scan wearing a query’s clothes, so it is refused rather
than served.