Skip to main content

TermDictionary

Struct TermDictionary 

Source
pub struct TermDictionary { /* private fields */ }
Expand description

A sorted, front-coded term dictionary.

Implementations§

Source§

impl TermDictionary

Source

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.

Source

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.

Source

pub fn len(&self) -> usize

Returns the number of terms.

Source

pub fn is_empty(&self) -> bool

Returns true when the dictionary holds no terms.

Source

pub fn encoded_bytes(&self) -> &[u8] ⓘ

Returns the front-coded bytes.

Source

pub fn term_at(&self, index: usize) -> Option<&[u8]>

Returns the term at a flat index.

Source

pub fn info_at(&self, index: usize) -> Option<TermInfo>

Returns the information at a flat index.

Source

pub fn get(&self, term: &[u8]) -> Option<TermInfo>

Looks one term up exactly.

Source

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.

Source

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.

Source

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.

Source

pub fn decode_terms(&self) -> Option<Vec<Vec<u8>>>

Decodes the front-coded bytes back into the term list.

Used by the golden test to prove the encoding is self-describing: the in-memory terms vector is a decode cache, not the source of truth for the persisted form.

Trait Implementations§

Source§

impl Clone for TermDictionary

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TermDictionary

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TermDictionary

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.