pub struct HashIndex { /* private fields */ }Expand description
Thread-scoped hash index for O(1) message lookup (REQ-309).
Each entry maps a ContentHash to its owning ThreadId and position
index within that thread. Lookups enforce thread isolation per ADR-008:
a lookup for hash H in thread T returns None if H belongs to thread T’.
Memory budget: <= 64 bytes per entry (NFR-303).
Implementations§
Source§impl HashIndex
impl HashIndex
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates an empty hash index with pre-allocated capacity.
Sourcepub fn insert(
&mut self,
hash: ContentHash,
thread: ThreadId,
index: usize,
) -> bool
pub fn insert( &mut self, hash: ContentHash, thread: ThreadId, index: usize, ) -> bool
Inserts a content hash mapped to a thread and position index.
Returns true if the entry was newly inserted, false if the hash
already existed (duplicate — entry is not overwritten).
Sourcepub fn lookup(&self, hash: &ContentHash, thread: &ThreadId) -> Option<usize>
pub fn lookup(&self, hash: &ContentHash, thread: &ThreadId) -> Option<usize>
Looks up a content hash, enforcing thread isolation (ADR-008).
Returns Some(index) only if the hash exists AND belongs to the given thread.
Returns None if the hash is absent or belongs to a different thread.
Sourcepub fn contains(&self, hash: &ContentHash, thread: &ThreadId) -> bool
pub fn contains(&self, hash: &ContentHash, thread: &ThreadId) -> bool
Checks whether a content hash exists in the given thread (ADR-008).
Returns true only if the hash exists AND belongs to the given thread.