turbo_tasks/graph/
non_deterministic.rs

1use super::graph_store::{GraphNode, GraphStore};
2
3/// A graph traversal that does not guarantee any particular order, and may not
4/// return the same order every time it is run.
5pub struct NonDeterministic<T> {
6    output: Vec<T>,
7}
8
9impl<T> Default for NonDeterministic<T> {
10    fn default() -> Self {
11        Self::new()
12    }
13}
14
15impl<T> NonDeterministic<T> {
16    pub fn new() -> Self {
17        Self { output: Vec::new() }
18    }
19}
20
21impl<T> GraphStore for NonDeterministic<T>
22where
23    T: Send,
24{
25    type Node = T;
26    type Handle = ();
27
28    fn insert(
29        &mut self,
30        _from_handle: Option<Self::Handle>,
31        node: GraphNode<T>,
32    ) -> Option<(Self::Handle, &T)> {
33        self.output.push(node.into_node());
34        Some(((), self.output.last().unwrap()))
35    }
36}
37
38impl<T> IntoIterator for NonDeterministic<T> {
39    type Item = T;
40    type IntoIter = <Vec<T> as IntoIterator>::IntoIter;
41
42    fn into_iter(self) -> Self::IntoIter {
43        self.output.into_iter()
44    }
45}