pub struct CacheKey(pub [u8; 32]);Expand description
Content-addressable hash identifying a computation.
Tuple Fields§
§0: [u8; 32]Implementations§
Source§impl CacheKey
impl CacheKey
Sourcepub fn from_parts(parts: &[&[u8]]) -> Self
pub fn from_parts(parts: &[&[u8]]) -> Self
Create a cache key by hashing arbitrary byte slices.
Sourcepub fn for_state(
config_hash: &CacheKey,
x_hash: &CacheKey,
y_hash: Option<&CacheKey>,
) -> Self
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).
Sourcepub fn for_output(
config_hash: &CacheKey,
state_hash: &CacheKey,
input_hash: &CacheKey,
) -> Self
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)
Sourcepub fn for_value(value: &Value) -> Self
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.