use std::collections::BTreeSet;
pub(super) struct ClaimTracker {
event_count: usize,
claimed: BTreeSet<usize>,
}
impl ClaimTracker {
pub(super) fn new(event_count: usize) -> Self {
Self {
event_count,
claimed: BTreeSet::new(),
}
}
pub(super) fn claim_available_indices(&mut self, indices: Vec<usize>) -> Vec<usize> {
indices
.into_iter()
.filter(|&index| self.claim_index(index))
.collect()
}
pub(super) fn orphan_indices(&self) -> Vec<usize> {
(0..self.event_count)
.filter(|index| !self.claimed.contains(index))
.collect()
}
fn claim_index(&mut self, index: usize) -> bool {
if index >= self.event_count || self.claimed.contains(&index) {
return false;
}
self.claimed.insert(index);
true
}
}