Implement Iterator for missing

This commit is contained in:
Jeremy Wall 2022-09-19 15:49:39 -04:00
parent 92ee369423
commit 44121516fc
2 changed files with 18 additions and 2 deletions

View File

@ -39,7 +39,7 @@ where
}
/// Returns the next set of missing [nodes](Node) in the iterator.
pub fn next(&mut self) -> Result<Option<Vec<Node<HW>>>> {
pub fn next_nodes(&mut self) -> Result<Option<Vec<Node<HW>>>> {
let nodes = self.dag.find_next_non_descendant_nodes(&self.root_nodes)?;
self.root_nodes = BTreeSet::new();
for id in nodes.iter().map(|n| n.id().to_vec()) {
@ -52,3 +52,19 @@ where
}
}
}
impl<'dag, S, HW> Iterator for Missing<'dag, S, HW>
where
S: Store<HW>,
HW: HashWriter,
{
type Item = Result<Vec<Node<HW>>>;
fn next(&mut self) -> Option<Self::Item> {
match self.next_nodes() {
Ok(Some(ns)) => Some(Ok(ns)),
Ok(None) => None,
Err(e) => Some(Err(e)),
}
}
}

View File

@ -155,7 +155,7 @@ where
}
/// Construct a [Missing] iterator for this dag given a set of remote root nodes.
pub fn missing_iter<'dag, 'iter>(
pub fn missing<'dag, 'iter>(
&'dag self,
search_nodes: BTreeSet<Vec<u8>>,
) -> Missing<'iter, S, HW>