hdrhistogram/iterators/
recorded.rs

1use crate::core::counter::Counter;
2use crate::iterators::{HistogramIterator, PickMetadata, PickyIterator};
3use crate::Histogram;
4
5/// An iterator that will yield only bins with at least one sample.
6pub struct Iter {
7    visited: Option<usize>,
8}
9
10impl Iter {
11    /// Construct a new sampled iterator. See `Histogram::iter_recorded` for details.
12    pub fn new<T: Counter>(hist: &Histogram<T>) -> HistogramIterator<T, Iter> {
13        HistogramIterator::new(hist, Iter { visited: None })
14    }
15}
16
17impl<T: Counter> PickyIterator<T> for Iter {
18    fn pick(&mut self, index: usize, _: u64, count_at_index: T) -> Option<PickMetadata> {
19        if count_at_index != T::zero() && self.visited.map(|i| i != index).unwrap_or(true) {
20            self.visited = Some(index);
21            return Some(PickMetadata::new(None, None));
22        }
23        None
24    }
25
26    fn more(&mut self, _: usize) -> bool {
27        false
28    }
29}