pub struct CompactDictionaryView<'a> { /* private fields */ }Expand description
Borrowed, Copy view over a compact dictionary’s buffers.
Like CompactDictionary its fields are private: a value can only be obtained
from an owned dictionary (Dictionary::as_view) or by validating raw borrowed
buffers with validate_safety,
validate, or
new_unchecked.
Implementations§
Source§impl<'a> CompactDictionaryView<'a>
impl<'a> CompactDictionaryView<'a>
Sourcepub fn validate_safety(
bytes: &'a [u8],
offsets: &'a [u32],
) -> Result<Self, InvalidColumn>
pub fn validate_safety( bytes: &'a [u8], offsets: &'a [u32], ) -> Result<Self, InvalidColumn>
Validate raw borrowed (bytes, offsets) for safe decoding over the same
slices (no copy) — the checked door across the safety boundary. The
borrowed bytes must already be read-padded (a borrow cannot be extended).
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) for safe decoding and correct
search 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 fn check_correctness(&self) -> Result<(), InvalidColumn>
pub fn check_correctness(&self) -> Result<(), InvalidColumn>
Check correctness-only invariants on an already safety-validated view.
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 view without checking.
§Safety
The slices must satisfy the structural invariants checked by
validate_safety, and must remain immutable and
stable for the lifetime of the returned view.
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 view already satisfies the structural invariants, so this never validates and never fails. Two 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.
When starting from raw DictionaryStorage rather than an existing
compact view, WideDictionary::validate_safety
materializes the wide form directly and avoids constructing an intermediate
CompactDictionary.
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.