MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / monotonic_counter

Function monotonic_counter

nodedb-codec/src/delta.rs:270–283  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

268
269 #[test]
270 fn monotonic_counter() {
271 // Bytes sent: monotonically increasing by ~1000 each step.
272 let values: Vec<i64> = (0..10_000).map(|i| i * 1000).collect();
273 let encoded = encode(&values);
274 let decoded = decode(&encoded).unwrap();
275 assert_eq!(decoded, values);
276
277 // All deltas are exactly 1000 → zigzag(1000) = 2000 → 2 bytes each.
278 let bytes_per_sample = encoded.len() as f64 / values.len() as f64;
279 assert!(
280 bytes_per_sample < 3.0,
281 "monotonic counter should compress to <3 bytes/sample, got {bytes_per_sample:.2}"
282 );
283 }
284
285 #[test]
286 fn counter_with_small_increments() {

Callers

nothing calls this directly

Calls 4

collectMethod · 0.80
encodeFunction · 0.70
decodeFunction · 0.70
lenMethod · 0.45

Tested by

no test coverage detected