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>
impl<'a> CompactDictionaryView<'a>
Sourcepub fn validate(
bytes: &'a [u8],
offsets: &'a [u32],
) -> Result<Self, InvalidColumn>
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
Sourcepub unsafe fn new_unchecked(bytes: &'a [u8], offsets: &'a [u32]) -> Self
pub unsafe fn new_unchecked(bytes: &'a [u8], offsets: &'a [u32]) -> Self
Seal raw borrowed (bytes, offsets) into a trusted view without checking.
§Safety
Sourcepub fn code_bits(&self) -> u8
pub fn code_bits(&self) -> u8
Minimum bits per code needed to address this dictionary,
ceil(log2(num_tokens)). See CompactDictionary::code_bits.
Sourcepub fn to_wide(&self) -> WideDictionary
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_SIZElength bound makeslens[id] = len as u8exact, not a silent truncation.
O(num_tokens), dominated by the row copy.
Trait Implementations§
Source§impl<'a> Clone for CompactDictionaryView<'a>
impl<'a> Clone for CompactDictionaryView<'a>
Source§fn clone(&self) -> CompactDictionaryView<'a>
fn clone(&self) -> CompactDictionaryView<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<'a> Copy for CompactDictionaryView<'a>
Source§impl<'a> Debug for CompactDictionaryView<'a>
impl<'a> Debug for CompactDictionaryView<'a>
Source§impl DictionaryView for CompactDictionaryView<'_>
impl DictionaryView for CompactDictionaryView<'_>
Source§fn num_tokens(&self) -> usize
fn num_tokens(&self) -> usize
0..num_tokens().Source§fn token(&self, id: Token) -> &[u8] ⓘ
fn token(&self, id: Token) -> &[u8] ⓘ
id. Bounds-checked; panics if id is out of range.