pub struct ZobristTable { /* private fields */ }Expand description
Zobrist hash table for O(1) incremental state hashing (Zobrist 1970).
Used by ZobristSnapshotter for efficient entropy detection.
Instead of computing SHA-256 every frame (O(N)), we can update the hash
incrementally when state changes (O(1)).
§Theory
Per Zobrist (1970): “A hash value can be updated incrementally by XORing out the old value and XORing in the new value.”
Per Tridgell (1999): “Rolling checksums enable efficient delta detection without full state comparison.”
§Examples
use jugar_web::trace::ZobristTable;
let table = ZobristTable::new(42);
let state = [0u8; 32];
let hash = table.hash_bytes(&state);
// Incremental update is O(1)
let new_hash = table.update_hash(hash, 0, 0, 255);
assert_ne!(hash, new_hash);Implementations§
Source§impl ZobristTable
impl ZobristTable
Sourcepub fn new(seed: u64) -> Self
pub fn new(seed: u64) -> Self
Create table with deterministic RNG (for reproducibility).
Uses xorshift64 for fast, deterministic random generation. Table is heap-allocated (65KB) to avoid stack overflow.
§Panics
Cannot panic - the Vec-to-array conversion is guaranteed to succeed
because we create exactly NUM_ZOBRIST_FIELDS elements.
Sourcepub fn hash_bytes(&self, bytes: &[u8]) -> u64
pub fn hash_bytes(&self, bytes: &[u8]) -> u64
Compute Zobrist hash for byte slice (O(N) - used once per state).
Trait Implementations§
Source§impl Clone for ZobristTable
impl Clone for ZobristTable
Source§fn clone(&self) -> ZobristTable
fn clone(&self) -> ZobristTable
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ZobristTable
impl Debug for ZobristTable
Auto Trait Implementations§
impl Freeze for ZobristTable
impl RefUnwindSafe for ZobristTable
impl Send for ZobristTable
impl Sync for ZobristTable
impl Unpin for ZobristTable
impl UnwindSafe for ZobristTable
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more