Skip to main content

CompactDictionaryView

Struct CompactDictionaryView 

Source
pub struct CompactDictionaryView<'a> { /* private fields */ }
Expand description

Borrowed, Copy, trusted view over a compact dictionary’s buffers.

Like CompactDictionary its fields are private: a value can only be obtained from a trusted owned dictionary (Dictionary::as_view) or by validating raw borrowed buffers with validate / new_unchecked.

Implementations§

Source§

impl<'a> CompactDictionaryView<'a>

Source

pub fn validate( bytes: &'a [u8], offsets: &'a [u32], ) -> Result<Self, InvalidColumn>

Validate raw borrowed (bytes, offsets) into a trusted view over the same slices (no copy) — the checked door across the trust boundary. The borrowed bytes must already be read-padded (a borrow cannot be extended).

§Errors

As CompactDictionary::validate.

Source

pub unsafe fn new_unchecked(bytes: &'a [u8], offsets: &'a [u32]) -> Self

Seal raw borrowed (bytes, offsets) into a trusted view without checking.

§Safety

As CompactDictionary::new_unchecked.

Source

pub fn code_bits(&self) -> u8

Minimum bits per code needed to address this dictionary, ceil(log2(num_tokens)). See CompactDictionary::code_bits.

Source

pub fn to_wide(&self) -> WideDictionary

Materialize the WideDictionary form: every token laid out in its own fixed MAX_TOKEN_SIZE-byte row, so a decode reaches a token at code * MAX_TOKEN_SIZE with no code → offset → bytes indirection. Worth building once to amortize over a bulk or repeated decode; see WideDictionary for the space/speed trade-off.

The source is a trusted CompactDictionaryView, so this never validates and never fails — the wide form is valid by construction. Two trusted invariants carry the build:

  • read-padding lets each row be filled with one fixed 16-byte copy from the token’s offset — an over-read past the token into neighbouring or padding bytes (harmless: decode only ever reads a row’s first lens[id] bytes), kept in bounds by the padding;
  • the ≤ MAX_TOKEN_SIZE length bound makes lens[id] = len as u8 exact, not a silent truncation.

O(num_tokens), dominated by the row copy.

Trait Implementations§

Source§

impl<'a> Clone for CompactDictionaryView<'a>

Source§

fn clone(&self) -> CompactDictionaryView<'a>

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<'a> Copy for CompactDictionaryView<'a>

Source§

impl<'a> Debug for CompactDictionaryView<'a>

Source§

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

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

impl DictionaryView for CompactDictionaryView<'_>

Source§

fn num_tokens(&self) -> usize

Number of tokens in the dictionary. The valid token ids are 0..num_tokens().
Source§

fn token(&self, id: Token) -> &[u8]

Bytes of token id. Bounds-checked; panics if id is out of range.
Source§

fn token_len(&self, id: Token) -> usize

Byte length of token id. Bounds-checked; panics if id is out of range.
Source§

unsafe fn token_ptr(&self, id: Token) -> *const u8

Raw pointer to token id’s bytes. Read more
Source§

unsafe fn token_len_unchecked(&self, id: Token) -> usize

Token id’s length — the unchecked counterpart of token_len. Read more
Source§

impl<'a> From<&'a CompactDictionary> for CompactDictionaryView<'a>

Source§

fn from(d: &'a CompactDictionary) -> Self

Converts to this type from the input type.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V