pub struct TensorChecksumEngine {
pub records: HashMap<u64, ChecksumRecord>,
pub stats: ChecksumEngineStats,
}Expand description
Stateful engine that manages per-tensor checksum records.
§Thread Safety
TensorChecksumEngine is not Send/Sync by default because it owns
a HashMap. Wrap in Arc<Mutex<…>> or parking_lot::Mutex for shared
access across threads.
§Examples
use ipfrs_tensorlogic::tensor_checksum::{ChecksumAlgorithm, TensorChecksumEngine};
let mut engine = TensorChecksumEngine::new();
let data = b"layer weights";
engine.compute(42, "fc1".to_string(), data, ChecksumAlgorithm::Adler32, 1_000_000);
assert_eq!(engine.verify(42, data), Some(true));
assert_eq!(engine.verify(99, data), None); // unknown id
assert!(engine.remove(42));
assert!(!engine.remove(42)); // already goneFields§
§records: HashMap<u64, ChecksumRecord>Per-tensor checksum records, keyed by tensor_id.
stats: ChecksumEngineStatsCumulative operational statistics.
Implementations§
Source§impl TensorChecksumEngine
impl TensorChecksumEngine
Sourcepub fn compute(
&mut self,
tensor_id: u64,
layer_name: String,
data: &[u8],
algorithm: ChecksumAlgorithm,
now_secs: u64,
) -> &ChecksumRecord
pub fn compute( &mut self, tensor_id: u64, layer_name: String, data: &[u8], algorithm: ChecksumAlgorithm, now_secs: u64, ) -> &ChecksumRecord
Compute a checksum for data, store the resulting ChecksumRecord,
increment stats.total_computed, and return a reference to the record.
If a record already exists for tensor_id, it is replaced.
§Parameters
tensor_id— Unique identifier for the tensor.layer_name— Human-readable layer name (e.g."encoder.layer1").data— Raw bytes of the tensor payload.algorithm— Checksum algorithm to use.now_secs— Current time as Unix seconds (caller-supplied for determinism in tests and embedded environments).
Sourcepub fn verify(&mut self, tensor_id: u64, data: &[u8]) -> Option<bool>
pub fn verify(&mut self, tensor_id: u64, data: &[u8]) -> Option<bool>
Verify the stored checksum for tensor_id against data.
- Returns
Noneiftensor_idis not registered. - Returns
Some(true)if the data matches. - Returns
Some(false)if the data does not match.
Both total_verified and (on failure) total_failures are updated.
Sourcepub fn remove(&mut self, tensor_id: u64) -> bool
pub fn remove(&mut self, tensor_id: u64) -> bool
Remove the record for tensor_id.
Returns true if the record existed and was removed, false if no
record was found for the given id.
Sourcepub fn stats(&self) -> &ChecksumEngineStats
pub fn stats(&self) -> &ChecksumEngineStats
Return a reference to the current engine statistics.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TensorChecksumEngine
impl RefUnwindSafe for TensorChecksumEngine
impl Send for TensorChecksumEngine
impl Sync for TensorChecksumEngine
impl Unpin for TensorChecksumEngine
impl UnsafeUnpin for TensorChecksumEngine
impl UnwindSafe for TensorChecksumEngine
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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