Skip to main content

streaming_crypto/core_api/parallelism/
policy.rs

1// ## 3. `src/parallelism/policy.rs`
2
3// Purpose: compaction policy + scheduler cycle.
4
5//! parallelism/policy.rs
6//! Hybrid compaction policy and scheduler cycle runner.
7
8pub struct HybridCompactionPolicy {
9    pub threshold: usize,
10    pub compacted: bool,
11}
12
13impl HybridCompactionPolicy {
14    pub fn new(threshold: usize) -> Self {
15        Self { threshold, compacted: false }
16    }
17
18    pub fn should_compact(&self, current_size: usize) -> bool {
19        current_size >= self.threshold
20    }
21
22    pub fn mark_compacted(&mut self) {
23        self.compacted = true;
24    }
25}
26
27/// Scheduler cycle runner
28pub fn spawn_scheduler_cycle(policy: &mut HybridCompactionPolicy, log_size: usize) {
29    if policy.should_compact(log_size) {
30        policy.mark_compacted();
31        // trigger compaction cycle
32    }
33}