Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions crates/zrx-graph/src/graph/traversal/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,6 @@ pub struct IntoIter {
// Trait implementations
// ----------------------------------------------------------------------------

impl Iterator for IntoIter {
type Item = usize;

/// Returns the next node.
#[inline]
fn next(&mut self) -> Option<Self::Item> {
let node = self.traversal.take()?;
self.traversal.complete(node).expect("invariant");
Some(node)
}

/// Returns the bounds of the traversal.
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
(self.traversal.len(), None)
}
}

// ----------------------------------------------------------------------------

impl IntoIterator for Traversal {
type Item = usize;
type IntoIter = IntoIter;
Expand Down Expand Up @@ -109,3 +89,23 @@ impl IntoIterator for Traversal {
IntoIter { traversal: self }
}
}

// ----------------------------------------------------------------------------

impl Iterator for IntoIter {
type Item = usize;

/// Returns the next node.
#[inline]
fn next(&mut self) -> Option<Self::Item> {
let node = self.traversal.take()?;
self.traversal.complete(node).expect("invariant");
Some(node)
}

/// Returns the bounds on the remaining length of the traversal.
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
(self.traversal.len(), None)
}
}
29 changes: 0 additions & 29 deletions crates/zrx-graph/src/graph/visitor/ancestors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,35 +111,6 @@ impl Iterator for Ancestors<'_> {
type Item = usize;

/// Returns the next ancestor.
///
/// # Examples
///
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_graph::Graph;
///
/// // Create graph builder and add nodes
/// let mut builder = Graph::builder();
/// let a = builder.add_node("a");
/// let b = builder.add_node("b");
/// let c = builder.add_node("c");
///
/// // Create edges between nodes
/// builder.add_edge(a, b, 0)?;
/// builder.add_edge(b, c, 0)?;
///
/// // Create graph from builder
/// let graph = builder.build();
///
/// // Create iterator over ancestors
/// let mut ancestors = graph.ancestors(c);
/// while let Some(node) = ancestors.next() {
/// println!("{node:?}");
/// }
/// # Ok(())
/// # }
/// ```
fn next(&mut self) -> Option<Self::Item> {
// Perform a depth-first search to find all ancestors of a node, by
// exploring them iteratively, not including the node itself
Expand Down
29 changes: 0 additions & 29 deletions crates/zrx-graph/src/graph/visitor/common_ancestors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,35 +126,6 @@ impl Iterator for CommonAncestors<'_> {
type Item = Vec<usize>;

/// Returns the next layer of common ancestors.
///
/// # Examples
///
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_graph::Graph;
///
/// // Create graph builder and add nodes
/// let mut builder = Graph::builder();
/// let a = builder.add_node("a");
/// let b = builder.add_node("b");
/// let c = builder.add_node("c");
///
/// // Create edges between nodes
/// builder.add_edge(a, b, 0)?;
/// builder.add_edge(a, c, 0)?;
///
/// // Create graph from builder
/// let graph = builder.build();
///
/// // Create iterator over common ancestors
/// let mut ancestors = graph.common_ancestors([b, c]);
/// while let Some(nodes) = ancestors.next() {
/// println!("{nodes:?}");
/// }
/// # Ok(())
/// # }
/// ```
fn next(&mut self) -> Option<Self::Item> {
if self.ancestors.is_empty() {
return None;
Expand Down
29 changes: 0 additions & 29 deletions crates/zrx-graph/src/graph/visitor/common_descendants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,35 +119,6 @@ impl Iterator for CommonDescendants<'_> {
type Item = Vec<usize>;

/// Returns the next layer of common descendants.
///
/// # Examples
///
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_graph::Graph;
///
/// // Create graph builder and add nodes
/// let mut builder = Graph::builder();
/// let a = builder.add_node("a");
/// let b = builder.add_node("b");
/// let c = builder.add_node("c");
///
/// // Create edges between nodes
/// builder.add_edge(a, c, 0)?;
/// builder.add_edge(b, c, 0)?;
///
/// // Create graph from builder
/// let graph = builder.build();
///
/// // Create iterator over common descendants
/// let mut descendants = graph.common_descendants([a, b]);
/// while let Some(nodes) = descendants.next() {
/// println!("{nodes:?}");
/// }
/// # Ok(())
/// # }
/// ```
fn next(&mut self) -> Option<Self::Item> {
if self.descendants.is_empty() {
return None;
Expand Down
29 changes: 0 additions & 29 deletions crates/zrx-graph/src/graph/visitor/descendants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,35 +111,6 @@ impl Iterator for Descendants<'_> {
type Item = usize;

/// Returns the next descendant.
///
/// # Examples
///
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_graph::Graph;
///
/// // Create graph builder and add nodes
/// let mut builder = Graph::builder();
/// let a = builder.add_node("a");
/// let b = builder.add_node("b");
/// let c = builder.add_node("c");
///
/// // Create edges between nodes
/// builder.add_edge(a, b, 0)?;
/// builder.add_edge(b, c, 0)?;
///
/// // Create graph from builder
/// let graph = builder.build();
///
/// // Create iterator over descendants
/// let mut descendants = graph.descendants(a);
/// while let Some(node) = descendants.next() {
/// println!("{node:?}");
/// }
/// # Ok(())
/// # }
/// ```
fn next(&mut self) -> Option<Self::Item> {
// Perform a depth-first search to find all descendants of a node, by
// exploring them iteratively, not including the node itself
Expand Down
29 changes: 0 additions & 29 deletions crates/zrx-graph/src/graph/visitor/filter_sinks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,35 +111,6 @@ impl Iterator for FilterSinks<'_> {
type Item = usize;

/// Returns the next sink.
///
/// # Examples
///
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_graph::Graph;
///
/// // Create graph builder and add nodes
/// let mut builder = Graph::builder();
/// let a = builder.add_node("a");
/// let b = builder.add_node("b");
/// let c = builder.add_node("c");
///
/// // Create edges between nodes
/// builder.add_edge(a, b, 0)?;
/// builder.add_edge(b, c, 0)?;
///
/// // Create graph from builder
/// let graph = builder.build();
///
/// // Create iterator over sinks
/// let mut sinks = graph.filter_sinks([a, b]);
/// while let Some(node) = sinks.next() {
/// println!("{node:?}");
/// }
/// # Ok(())
/// # }
/// ```
fn next(&mut self) -> Option<Self::Item> {
while self.index < self.nodes.len() {
let node = self.nodes[self.index];
Expand Down
29 changes: 0 additions & 29 deletions crates/zrx-graph/src/graph/visitor/filter_sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,35 +111,6 @@ impl Iterator for FilterSources<'_> {
type Item = usize;

/// Returns the next source.
///
/// # Examples
///
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_graph::Graph;
///
/// // Create graph builder and add nodes
/// let mut builder = Graph::builder();
/// let a = builder.add_node("a");
/// let b = builder.add_node("b");
/// let c = builder.add_node("c");
///
/// // Create edges between nodes
/// builder.add_edge(a, b, 0)?;
/// builder.add_edge(b, c, 0)?;
///
/// // Create graph from builder
/// let graph = builder.build();
///
/// // Create iterator over sources
/// let mut sources = graph.filter_sources([b, c]);
/// while let Some(node) = sources.next() {
/// println!("{node:?}");
/// }
/// # Ok(())
/// # }
/// ```
fn next(&mut self) -> Option<Self::Item> {
while self.index < self.nodes.len() {
let node = self.nodes[self.index];
Expand Down
29 changes: 0 additions & 29 deletions crates/zrx-graph/src/graph/visitor/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,35 +107,6 @@ impl Iterator for Paths<'_> {
type Item = Vec<usize>;

/// Returns the next path.
///
/// # Examples
///
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_graph::Graph;
///
/// // Create graph builder and add nodes
/// let mut builder = Graph::builder();
/// let a = builder.add_node("a");
/// let b = builder.add_node("b");
/// let c = builder.add_node("c");
///
/// // Create edges between nodes
/// builder.add_edge(a, b, 0)?;
/// builder.add_edge(b, c, 0)?;
///
/// // Create graph from builder
/// let graph = builder.build();
///
/// // Create iterator over paths
/// let mut paths = graph.paths(a, c);
/// while let Some(path) = paths.next() {
/// println!("{path:?}");
/// }
/// # Ok(())
/// # }
/// ```
fn next(&mut self) -> Option<Self::Item> {
// Perform a depth-first search to find all paths from the source to
// the target, and emit them in the order of discovery
Expand Down
29 changes: 0 additions & 29 deletions crates/zrx-graph/src/graph/visitor/sinks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,35 +95,6 @@ impl Iterator for Sinks<'_> {
type Item = usize;

/// Returns the next sink.
///
/// # Examples
///
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_graph::Graph;
///
/// // Create graph builder and add nodes
/// let mut builder = Graph::builder();
/// let a = builder.add_node("a");
/// let b = builder.add_node("b");
/// let c = builder.add_node("c");
///
/// // Create edges between nodes
/// builder.add_edge(a, b, 0)?;
/// builder.add_edge(b, c, 0)?;
///
/// // Create graph from builder
/// let graph = builder.build();
///
/// // Create iterator over sinks
/// let mut sinks = graph.sinks();
/// while let Some(node) = sinks.next() {
/// println!("{node:?}");
/// }
/// # Ok(())
/// # }
/// ```
fn next(&mut self) -> Option<Self::Item> {
while self.index < self.outgoing.len() {
let node = self.index;
Expand Down
29 changes: 0 additions & 29 deletions crates/zrx-graph/src/graph/visitor/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,35 +95,6 @@ impl Iterator for Sources<'_> {
type Item = usize;

/// Returns the next source.
///
/// # Examples
///
/// ```
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// use zrx_graph::Graph;
///
/// // Create graph builder and add nodes
/// let mut builder = Graph::builder();
/// let a = builder.add_node("a");
/// let b = builder.add_node("b");
/// let c = builder.add_node("c");
///
/// // Create edges between nodes
/// builder.add_edge(a, b, 0)?;
/// builder.add_edge(b, c, 0)?;
///
/// // Create graph from builder
/// let graph = builder.build();
///
/// // Create iterator over sources
/// let mut sources = graph.sources();
/// while let Some(node) = sources.next() {
/// println!("{node:?}");
/// }
/// # Ok(())
/// # }
/// ```
fn next(&mut self) -> Option<Self::Item> {
while self.index < self.incoming.len() {
let node = self.index;
Expand Down
Loading