Skip to main content

Crate neoset

Crate neoset 

Source
Expand description

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:

TagMeaningPayload
00Run of N zerosN (62-bit count)
10Run of N onesN (62-bit count)
D1Literal63 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 neoset::{EventSet, EventSetBuilder};

// Dense: "I have all events 0..999"
let dense = EventSet::ones(1000);
assert_eq!(dense.count_ones(), 1000);

// Sparse: "I have events 5, 100, 5000 out of 10000"
let sparse = EventSet::from_ones(&[5, 100, 5000], 10_000);
assert_eq!(sparse.count_ones(), 3);

// Sync diff: what does peer A have that peer B doesn't?
let peer_a = EventSet::ones(1000);
let mut b = EventSetBuilder::new();
b.push_ones(800);
b.push_zeros(50);
b.push_ones(150);
let peer_b = b.finish();
let need: Vec<u64> = peer_a.difference(&peer_b).iter_ones().collect();
assert_eq!(need.len(), 50); // events 800..850

Structs§

EventSet
A compact, RLE-encoded bitset.
EventSetBuilder
Incremental builder for EventSet.
Iter
Iterator over bit indices matching a target value.