Skip to main content

Module key

Module key 

Source
Expand description

Key: stable node identity across frames.

A key is a hash of the path from the root: each node’s key is its parent’s mixed with either a string label or a sibling index. The same logical widget therefore gets the same key every frame, retained state (focus, scroll offsets, edit buffers, tweens) is looked up by it, and a binding can reproduce a key from strings alone.

use kui_core::Key;

let list = Key::ROOT.str("list");
assert_eq!(list.index(3), Key::ROOT.str("list").index(3));
assert_ne!(list.str("3"), list.index(3)); // labels and indices never clash

Structs§

Key
A node’s identity: the hash of its path from the root. Key::ROOT is the tree’s root; Key::str and Key::index derive children.

Constants§

FNV_OFFSET
The FNV-1a basis every hash in the core starts from — keys, the text cache’s identities, the access tree’s digest, the corpus digest.
FNV_PRIME

Functions§

fnv
FNV-1a over bytes, continuing from h. The one spelling of the mixer: a digest that must stay bit-stable across versions (a key, the access tree’s change detector, the corpus digest) is stable because it is this function and nothing else. A byte a round with a multiply on the chain — a nanosecond a byte — which is the right cost for a label and the wrong one for a megabyte of text: that goes through hash_bulk first.
hash_bulk
A word-wide hash of bytes (eight a round where fnv takes one), for the bulk a text cache key is made of. Fx’s round (rotate, xor, multiply) with the length mixed first and murmur’s finalizer after, so a tail of zero bytes and a shorter text differ and every input bit reaches every output bit. Not a digest anything keeps across versions.
mix_content
Mixes content into a key: short content by the byte, long content through hash_bulk and its eight bytes by the byte.