Skip to content

Instantly share code, notes, and snippets.

@EntilZha
Last active March 8, 2016 23:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EntilZha/a266153de2e2248251a6 to your computer and use it in GitHub Desktop.
Save EntilZha/a266153de2e2248251a6 to your computer and use it in GitHub Desktop.
pub struct BfsIterator<'a, V: 'a + Copy, E: 'a + Copy> {
queue: VecDeque<VertexId>,
graph: &'a Graph<V, E>,
distances: Vec<u64>,
parents: Vec<VertexId>,
predicate: &'a Fn(V, E, V) -> bool
}
impl<'a, V: Copy, E: Copy> Graph<V, E> {
pub fn bfs_iter(&'a self, source: VertexId) -> BfsIterator<V, E> {
let f: &'a Fn(V, E, V) -> bool = &bfs_true_predicate;
BfsIterator::new(self, source, f)
}
pub fn bfs_iter_predicate<'b>(&'b self, source: VertexId, predicate: &'b Fn(V, E, V) -> bool) -> BfsIterator<V, E> {
BfsIterator::new(self, source, predicate)
}
}
fn bfs_true_predicate<'a, V: Copy, E: Copy>(source: V, edge: E, destination: V) -> bool {
true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment