Skip to content

Commit

Permalink
Disable DfsIter and BfsIter until bug rust-lang/rust#22841 is fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Mar 3, 2015
1 parent 4f47404 commit 5973936
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 64 deletions.
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ pub use graph::Graph;
pub use self::EdgeDirection::{Outgoing, Incoming};
pub use visit::{
Bfs,
BfsIter,
Dfs,
DfsIter,
};

mod scored;
Expand Down
57 changes: 0 additions & 57 deletions src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,34 +257,6 @@ impl<N, VM> Dfs<N, VM> where
}
}

/// An iterator for a depth first traversal of a graph.
pub struct DfsIter<'a, G: 'a + Visitable>
{
graph: &'a G,
dfs: Dfs<G::NodeId, G::Map>,
}

impl<'a, G: Visitable> DfsIter<'a, G>
{
pub fn new(graph: &'a G, start: G::NodeId) -> Self
{
DfsIter {
graph: graph,
dfs: Dfs::new(graph, start)
}
}
}

impl<'a, G: 'a + Visitable> Iterator for DfsIter<'a, G> where
G: for<'b> NeighborIter<'b>,
{
type Item = G::NodeId;
fn next(&mut self) -> Option<G::NodeId>
{
self.dfs.next(self.graph)
}
}

/// A breadth first search (BFS) of a graph.
///
/// Using a **Bfs** you can run a traversal over a graph while still retaining
Expand Down Expand Up @@ -373,32 +345,3 @@ pub fn visitor<G>(graph: &G, start: <G as Graphlike>::NodeId) -> Visitor<G> wher
}
*/

/// An iterator for a breadth first traversal of a graph.
pub struct BfsIter<'a, G: 'a + Visitable>
{
graph: &'a G,
bfs: Bfs<G::NodeId, G::Map>,
}

impl<'a, G: Visitable> BfsIter<'a, G> where
G::NodeId: Clone,
{
pub fn new(graph: &'a G, start: G::NodeId) -> Self
{
BfsIter {
graph: graph,
bfs: Bfs::new(graph, start)
}
}
}

impl<'a, G: 'a + Visitable> Iterator for BfsIter<'a, G> where
G::NodeId: Clone,
G: for<'b> NeighborIter<'b>,
{
type Item = G::NodeId;
fn next(&mut self) -> Option<G::NodeId>
{
self.bfs.next(self.graph)
}
}
5 changes: 2 additions & 3 deletions tests/graphmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ extern crate petgraph;
use petgraph::{
GraphMap,
};
use petgraph::visit::{
DfsIter,
};

use petgraph::algo::{
dijkstra,
Expand Down Expand Up @@ -87,8 +84,10 @@ fn dfs() {
gr.add_edge(i, j, 1.);
gr.add_edge(i, k, 2.);

/*
assert_eq!(DfsIter::new(&gr, h).count(), 4);
assert_eq!(DfsIter::new(&gr, i).count(), 4);
assert_eq!(DfsIter::new(&gr, z).count(), 1);
*/
}

8 changes: 6 additions & 2 deletions tests/ograph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use std::iter::AdditiveIterator;
use petgraph::{
Graph,
Bfs,
BfsIter,
Dfs,
DfsIter,
Incoming,
Outgoing,
Directed,
Expand Down Expand Up @@ -84,6 +82,7 @@ fn dfs() {
gr.add_edge(i, j, 1.);
gr.add_edge(i, k, 2.);

/*
assert_eq!(DfsIter::new(&gr, h).count(), 4);
assert_eq!(DfsIter::new(&Reversed(&gr), h).count(), 1);
Expand All @@ -93,6 +92,7 @@ fn dfs() {
assert_eq!(DfsIter::new(&gr, i).count(), 3);
assert_eq!(DfsIter::new(&AsUndirected(&gr), i).count(), 4);
*/

}

Expand All @@ -111,6 +111,7 @@ fn bfs() {
gr.add_edge(i, j, 1.);
gr.add_edge(i, k, 2.);

/*
assert_eq!(BfsIter::new(&gr, h).count(), 4);
assert_eq!(BfsIter::new(&Reversed(&gr), h).count(), 1);
Expand All @@ -120,6 +121,7 @@ fn bfs() {
assert_eq!(BfsIter::new(&gr, i).count(), 3);
assert_eq!(BfsIter::new(&AsUndirected(&gr), i).count(), 4);
*/

let mut bfs = Bfs::new(&gr, h);
let nx = bfs.next(&gr);
Expand Down Expand Up @@ -302,9 +304,11 @@ fn dijk() {
g.add_edge(c, f, 11);
g.add_edge(e, f, 6);
println!("{:?}", g);
/*
for no in BfsIter::new(&g, a) {
println!("Visit {:?} = {:?}", no, g.node_weight(no));
}
*/

let scores = dijkstra(&g, a, None, |gr, n| gr.edges(n).map(|(n, &e)| (n, e)));
let mut scores: Vec<_> = scores.into_iter().map(|(n, s)| (g[n], s)).collect();
Expand Down

0 comments on commit 5973936

Please sign in to comment.