Skip to main content

VocabularyHandle

Struct VocabularyHandle 

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

An immutable, opaque handle owning ONE canonical vocabulary representation and its content fingerprint - always computed here, never caller-suppliable.

Implementations§

Source§

impl VocabularyHandle

Source

pub fn new(vocab: Arc<Vocabulary>) -> Result<Self, CompileError>

Wraps vocab, building the canonical representation once, admitted against the shared build-memory gate so concurrent large constructions cannot each exceed the process budget.

Source

pub fn new_with_logits_vocab_size( vocab: Arc<Vocabulary>, logits_vocab_size: Option<usize>, ) -> Result<Self, CompileError>

new, with an explicit mask width instead of the inferred one. Rejected if Some and smaller than the largest token/EOS id actually present.

Source

pub fn new_admitted( vocab: Arc<Vocabulary>, permit: &PermitGuard<'_>, ) -> Result<Self, CompileError>

new, but the caller already holds a PermitGuard for this whole operation - re-verified against this route’s own estimate first, so an undersized permit is rejected, not trusted.

Source

pub fn new_admitted_with_logits_vocab_size( vocab: Arc<Vocabulary>, logits_vocab_size: Option<usize>, permit: &PermitGuard<'_>, ) -> Result<Self, CompileError>

new_admitted, with the same explicit-mask-width contract as new_with_logits_vocab_size.

Source

pub fn from_packed( token_bytes: &[u8], byte_offsets: &[u32], token_ids: &[u32], id_offsets: &[u32], eos_token_id: u32, ) -> Result<Self, CompileError>

Builds directly from four packed CSR buffers (the tuple-free fast path): no intermediate Vocabulary/HashMap. Same validation as new, admitted before any construction runs.

Source

pub fn from_packed_with_logits_vocab_size( token_bytes: &[u8], byte_offsets: &[u32], token_ids: &[u32], id_offsets: &[u32], eos_token_id: u32, logits_vocab_size: Option<usize>, ) -> Result<Self, CompileError>

from_packed, with the same explicit-mask-width contract as new_with_logits_vocab_size.

Source

pub fn from_packed_admitted( token_bytes: &[u8], byte_offsets: &[u32], token_ids: &[u32], id_offsets: &[u32], eos_token_id: u32, permit: &PermitGuard<'_>, ) -> Result<Self, CompileError>

from_packed, but the caller already holds a PermitGuard covering the whole ingestion - re-verified the same way as new_admitted, from the actual slices.

Source

pub fn from_packed_admitted_with_logits_vocab_size( token_bytes: &[u8], byte_offsets: &[u32], token_ids: &[u32], id_offsets: &[u32], eos_token_id: u32, logits_vocab_size: Option<usize>, permit: &PermitGuard<'_>, ) -> Result<Self, CompileError>

from_packed_admitted, with the same explicit-mask-width contract as new_with_logits_vocab_size.

Source

pub fn from_dense_id_ordered( token_bytes: &[u8], byte_offsets: &[u32], present: &[bool], eos_token_id: u32, ) -> Result<Self, CompileError>

Builds directly from a DENSE, ID-ORDERED tokenizer decode: decoded[i] (via byte_offsets) is token id i’s bytes, present[i] says whether slot i exists. No id list, no

Source

pub fn from_dense_id_ordered_with_logits_vocab_size( token_bytes: &[u8], byte_offsets: &[u32], present: &[bool], eos_token_id: u32, logits_vocab_size: Option<usize>, ) -> Result<Self, CompileError>

from_dense_id_ordered, with the same explicit-mask-width contract as new_with_logits_vocab_size.

Source

pub fn from_dense_id_ordered_admitted( token_bytes: &[u8], byte_offsets: &[u32], present: &[bool], eos_token_id: u32, permit: &PermitGuard<'_>, ) -> Result<Self, CompileError>

from_dense_id_ordered, but the caller already holds a PermitGuard covering the whole ingestion - re-verified from the actual slices, same as from_packed_admitted.

Source

pub fn from_dense_id_ordered_admitted_with_logits_vocab_size( token_bytes: &[u8], byte_offsets: &[u32], present: &[bool], eos_token_id: u32, logits_vocab_size: Option<usize>, permit: &PermitGuard<'_>, ) -> Result<Self, CompileError>

from_dense_id_ordered_admitted, with the same explicit-mask-width contract as new_with_logits_vocab_size.

Source

pub fn fingerprint(&self) -> VocabFingerprint

The vocabulary’s content fingerprint, computed once at construction.

Source

pub fn mask_vocab_size(&self) -> usize

The mask width (max(largest token id, EOS id) + 1, or the explicit logits_vocab_size this handle was built with) - the number of bits one mask row covers.

Source

pub fn eos_token_id(&self) -> u32

The EOS token id (a side value, never a mask bit).

Source

pub fn len(&self) -> usize

The number of stored ordinary token ids plus one for EOS (NOT the distinct byte-string count and NOT the mask width).

Source

pub fn is_empty(&self) -> bool

True when the token map has no records (matches Vocabulary::is_empty()).

Source

pub fn token_bytes(&self, id: u32) -> Option<&[u8]>

id’s byte string, or None if id names no ordinary token (including EOS).

Source

pub fn iter_records(&self) -> impl Iterator<Item = (&[u8], &[u32])>

Every record as (bytes, ids), byte-sorted (for a caller with no precomputed mask table).

Source

pub fn token_slice_retained_bytes(&self) -> usize

Bytes retained by the optional vocabulary-derived token-slice catalogue.

Trait Implementations§

Source§

impl Clone for VocabularyHandle

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 VocabularyHandle

Source§

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

Formats the value using the given formatter. 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.