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

Function monotonic_with_jitter

nodedb-codec/src/double_delta.rs:400–419  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

398
399 #[test]
400 fn monotonic_with_jitter() {
401 let mut values = Vec::with_capacity(10_000);
402 let mut ts = 1_700_000_000_000i64;
403 let mut rng: u64 = 42;
404 for _ in 0..10_000 {
405 values.push(ts);
406 rng = rng.wrapping_mul(6364136223846793005).wrapping_add(1);
407 let jitter = ((rng >> 33) as i64 % 101) - 50;
408 ts += 10_000 + jitter;
409 }
410 let encoded = encode(&values);
411 let decoded = decode(&encoded).unwrap();
412 assert_eq!(decoded, values);
413
414 let bytes_per_sample = encoded.len() as f64 / values.len() as f64;
415 assert!(
416 bytes_per_sample < 2.0,
417 "jittered timestamps should compress to <2 bytes/sample, got {bytes_per_sample:.2}"
418 );
419 }
420
421 #[test]
422 fn non_monotonic_values() {

Callers

nothing calls this directly

Calls 4

encodeFunction · 0.70
decodeFunction · 0.70
pushMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected