1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use super::{ChunkView, Hff};
use std::fmt::Debug;

/// Iterator over a table's chunks.
pub struct ChunkIter<'a, T: Debug> {
    hff: &'a Hff<T>,
    current: isize,
    count: usize,
}

impl<'a, T: Debug> ChunkIter<'a, T> {
    /// Create a new chunk iterator.
    pub fn new(hff: &'a Hff<T>, index: usize, count: usize) -> Self {
        Self {
            hff,
            current: index as isize - 1,
            count,
        }
    }
}

impl<'a, T: Debug> Iterator for ChunkIter<'a, T> {
    type Item = ChunkView<'a, T>;

    fn next(&mut self) -> Option<Self::Item> {
        if self.count > 0 {
            self.count -= 1;
            self.current += 1;
            Some(ChunkView::new(self.hff, self.current as usize))
        } else {
            None
        }
    }
}