use super::{Interaction, Label, Stats, Visit};
use std::collections::HashMap;
pub struct Gate {
visits: Vec<Visit>,
}
impl Gate {
pub fn turn<'l>(&mut self, labels: impl IntoIterator<Item = &'l Label<'l>>) -> Interaction {
let (visit, expectation) =
Visit::interaction(labels.into_iter().map(|l| l.anon()).collect());
self.visits.push(visit);
expectation
}
pub fn stats(&mut self) -> HashMap<Label<'static>, Stats> {
let mut stats = HashMap::with_capacity(self.visits.len() * 5);
for visit in &mut self.visits {
let counters = visit.check();
for label in visit.labels() {
stats
.entry(label)
.or_insert_with(|| Stats::default())
.add(counters);
}
}
stats
}
pub fn count(&self) -> usize {
self.visits.len()
}
}