File size: 991 Bytes
1e92f2d |
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 35 36 37 38 39 40 41 42 43 44 45 46 |
use super::graph_store::{GraphNode, GraphStore};
/// A graph traversal that does not guarantee any particular order, and may not
/// return the same order every time it is run.
pub struct NonDeterministic<T> {
output: Vec<T>,
}
impl<T> Default for NonDeterministic<T> {
fn default() -> Self {
Self::new()
}
}
impl<T> NonDeterministic<T> {
pub fn new() -> Self {
Self { output: Vec::new() }
}
}
impl<T> GraphStore for NonDeterministic<T>
where
T: Send,
{
type Node = T;
type Handle = ();
fn insert(
&mut self,
_from_handle: Option<Self::Handle>,
node: GraphNode<T>,
) -> Option<(Self::Handle, &T)> {
self.output.push(node.into_node());
Some(((), self.output.last().unwrap()))
}
}
impl<T> IntoIterator for NonDeterministic<T> {
type Item = T;
type IntoIter = <Vec<T> as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
self.output.into_iter()
}
}
|