mirror of
https://github.com/zaphar/merkle-dag.git
synced 2025-07-21 18:19:58 -04:00
Implement Iterator for missing
This commit is contained in:
parent
92ee369423
commit
44121516fc
@ -39,7 +39,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the next set of missing [nodes](Node) in the iterator.
|
/// 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)?;
|
let nodes = self.dag.find_next_non_descendant_nodes(&self.root_nodes)?;
|
||||||
self.root_nodes = BTreeSet::new();
|
self.root_nodes = BTreeSet::new();
|
||||||
for id in nodes.iter().map(|n| n.id().to_vec()) {
|
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)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -155,7 +155,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a [Missing] iterator for this dag given a set of remote root nodes.
|
/// 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,
|
&'dag self,
|
||||||
search_nodes: BTreeSet<Vec<u8>>,
|
search_nodes: BTreeSet<Vec<u8>>,
|
||||||
) -> Missing<'iter, S, HW>
|
) -> Missing<'iter, S, HW>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user