Skip to main content

RollingHashIdMapper

Struct RollingHashIdMapper 

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

Maps sequence-aware block hashes to compact, stable u64 ids.

The mapper is intentionally stateful and reusable across requests/turns: a block of tokens that appears at the same prefix position in two different requests will be assigned the same id. Equality of leading hash_ids between rows therefore signals shared prompt prefixes for replay purposes.

hash_ids here are workload identity labels, not literal Dynamo runtime KV-cache hashes. Producers should not try to reconcile them with a production cache.

Implementations§

Source§

impl RollingHashIdMapper

Source

pub fn new(block_size: usize) -> Self

Create a new mapper for the given block size.

Source

pub fn block_size(&self) -> usize

Block size that this mapper was constructed with.

Source

pub fn hash_token_blocks(&mut self, tokens: &[u32]) -> Vec<u64>

Hash a sequence of tokens into Mooncake hash_ids.

Tokens are chunked by block_size; each complete block contributes one compact id derived from Dynamo’s shared KV-hashing contract. A trailing partial block also contributes one compact id so replay capacity still covers the full prompt length. Identical prefixes across requests resolve to identical leading hash_ids once the mapper has seen them.

Source

pub fn try_hash_token_blocks(&mut self, tokens: &[u32]) -> Result<Vec<u64>>

Fallible variant of Self::hash_token_blocks.

Source

pub fn ids_for_sequence_hashes(&mut self, sequence_hashes: &[u64]) -> Vec<u64>

Map precomputed sequence-aware block hashes into compact Mooncake IDs.

This is useful for producers that record stable block hashes in the serving path and only compact them during offline trace conversion.

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> 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, 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.