hff_core/read/
depth_first_iter.rs1use super::{Hff, TableView};
2use std::fmt::Debug;
3
4pub struct DepthFirstIter<'a, T: Debug> {
6 hff: &'a Hff<T>,
8 index: usize,
10 count: Vec<usize>,
12}
13
14impl<'a, T: Debug> DepthFirstIter<'a, T> {
15 pub fn new(hff: &'a Hff<T>) -> DepthFirstIter<'a, T> {
17 Self {
18 hff,
19 index: 0,
20 count: vec![],
21 }
22 }
23}
24
25impl<'a, T: Debug> Iterator for DepthFirstIter<'a, T> {
26 type Item = (usize, TableView<'a, T>);
28
29 fn next(&mut self) -> Option<Self::Item> {
30 let tables = self.hff.tables_array();
31
32 if self.index < tables.len() {
33 let table = &tables[self.index];
35
36 while let Some(top) = self.count.pop() {
38 if top > 0 {
39 self.count.push(top - 1);
40 break;
41 }
42 }
43
44 let depth = self.count.len();
46
47 if table.child_count() > 0 {
49 self.count.push(table.child_count() as usize);
50 }
51
52 let view = TableView::new(self.hff, self.index);
53 self.index += 1;
54
55 Some((depth, view))
56 } else {
57 None
59 }
60 }
61}