Skip to main content

CacheKey

Struct CacheKey 

Source
pub struct CacheKey(pub [u8; 32]);
Expand description

Content-addressable hash identifying a computation.

Tuple Fields§

§0: [u8; 32]

Implementations§

Source§

impl CacheKey

Source

pub fn from_parts(parts: &[&[u8]]) -> Self

Create a cache key by hashing arbitrary byte slices.

Source

pub fn for_state( config_hash: &CacheKey, x_hash: &CacheKey, y_hash: Option<&CacheKey>, ) -> Self

Create a cache key for a filter’s trained state. key = hash(filter_config_hash + x_hash [+ y_hash])

The labels y are part of the key: the same features trained against different labels must never collide. None and Some(...) always produce distinct keys (different part counts, and every part is length-prefixed).

Source

pub fn for_output( config_hash: &CacheKey, state_hash: &CacheKey, input_hash: &CacheKey, ) -> Self

Create a cache key for a filter’s output. key = hash(filter_config_hash + state_hash + input_data_hash)

Source

pub fn hash_data(data: &[u8]) -> Self

Hash arbitrary serializable data.

Source

pub fn for_value(value: &Value) -> Self

Hash a Value for use as cache-key material.

Not hash_data(serde_json::to_vec(value)), which is what the runtime used to do. JSON has no way to write a non-finite float: serde_json turns NaN and every infinity into null, silently. A tensor of NaN and a tensor of +∞ therefore serialized to the same bytes, hashed to the same key, and the second one was answered with the first one’s cached output.

Floats are hashed by their bit pattern instead, so every distinct value gets a distinct key. Two consequences worth knowing: the two NaN encodings are different keys (they are different bit patterns), and 0.0 and -0.0 are different keys too. Both are the safe direction — a redundant miss costs a recomputation, a false hit costs a wrong answer.

Source

pub fn to_hex(&self) -> String

Returns the hex representation.

Trait Implementations§

Source§

impl Clone for CacheKey

Source§

fn clone(&self) -> CacheKey

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 CacheKey

Source§

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

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

impl<'de> Deserialize<'de> for CacheKey

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for CacheKey

Source§

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

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

impl Eq for CacheKey

Source§

impl Hash for CacheKey

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for CacheKey

Source§

fn eq(&self, other: &CacheKey) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for CacheKey

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for CacheKey

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> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

The receiver as &dyn Any, ready for downcast_ref.
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> Same for T

Source§

type Output = T

Should always be Self
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.