Module hybrid_batcher

Module hybrid_batcher 

Source
Expand description

Hybrid batching for efficient writes.

The HybridBatcher collects items and flushes them in batches based on configurable thresholds: item count, total bytes, or elapsed time.

§Example

use sync_engine::{HybridBatcher, BatchConfig, SizedItem};

#[derive(Clone)]
struct Item { data: String }
impl SizedItem for Item {
    fn size_bytes(&self) -> usize { self.data.len() }
}

let config = BatchConfig {
    flush_ms: 100,
    flush_count: 10,
    flush_bytes: 1024,
};

let mut batcher: HybridBatcher<Item> = HybridBatcher::new(config);
assert!(batcher.is_empty());

batcher.add(Item { data: "hello".into() });
assert!(!batcher.is_empty());

Structs§

Batch
A batch of items pending flush
BatchConfig
Configuration for hybrid batching
FlushBatch
A batch of items ready for flush
HybridBatcher
Hybrid batcher that flushes based on time, count, or size thresholds. Whichever threshold is hit first triggers the flush.

Enums§

FlushReason
Batch flush trigger reason

Traits§

BatchableItem
Trait for items that have an ID (for contains check)
SizedItem
Trait for items that know their own size