Compact RLE-encoded event sets.
An [EventSet] tracks which events (by index) a peer has seen,
using a hybrid run-length / literal encoding for efficient storage
across sparse, dense, and random data patterns.
Encoding
Each 64-bit block uses a 2-bit tag in the MSBs:
| Tag | Meaning | Payload |
|---|---|---|
00 |
Run of N zeros | N (62-bit count) |
10 |
Run of N ones | N (62-bit count) |
D1 |
Literal | 63 raw bits |
A literal block packs 63 bits into 64: bit 62 is the literal tag, bit 63 is the MSB of the 63-bit value, and bits 61..0 hold the lower 62 bits. Runs compress homogeneous regions; literals compress mixed/random regions.
Examples
use ;
// Dense: "I have all events 0..999"
let dense = ones;
assert_eq!;
// Sparse: "I have events 5, 100, 5000 out of 10000"
let sparse = from_ones;
assert_eq!;
// Sync diff: what does peer A have that peer B doesn't?
let peer_a = ones;
let mut b = new;
b.push_ones;
b.push_zeros;
b.push_ones;
let peer_b = b.finish;
let need: = peer_a.difference.iter_ones.collect;
assert_eq!; // events 800..850