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

Function compression_with_many_ops

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

Source from the content-addressed store, hash-verified

281
282 #[test]
283 fn compression_with_many_ops() {
284 let mut ops = Vec::new();
285 for i in 0..1000 {
286 ops.push(CrdtOp {
287 lamport: i,
288 actor_id: i % 5, // 5 actors
289 content: format!("op-{i}: set key_{} = value_{}", i % 50, i).into_bytes(),
290 });
291 }
292 let encoded = encode(&ops).unwrap();
293 let decoded = decode(&encoded).unwrap();
294
295 assert_eq!(decoded.len(), 1000);
296 for (orig, dec) in ops.iter().zip(decoded.iter()) {
297 assert_eq!(orig.lamport, dec.lamport);
298 assert_eq!(orig.actor_id, dec.actor_id);
299 assert_eq!(orig.content, dec.content);
300 }
301
302 // Should compress well — monotonic lamports + few actors + repetitive content.
303 let raw_size: usize = ops.iter().map(|op| 16 + op.content.len()).sum();
304 let ratio = raw_size as f64 / encoded.len() as f64;
305 assert!(
306 ratio > 1.2,
307 "CRDT ops should compress >1.2x, got {ratio:.2}x"
308 );
309 }
310
311 #[test]
312 fn actor_dictionary_dedup() {

Callers

nothing calls this directly

Calls 6

sumMethod · 0.80
encodeFunction · 0.70
decodeFunction · 0.70
pushMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected