Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IntoEdgesDirected implementation for NodeFiltered when direction is Incoming #476

Merged
merged 1 commit into from Jun 10, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/visit/filter.rs
Expand Up @@ -263,6 +263,7 @@ where
include_source: self.1.include_node(a),
iter: self.0.edges(a),
f: &self.1,
dir: Direction::Outgoing,
}
}
}
Expand All @@ -279,6 +280,7 @@ where
include_source: self.1.include_node(a),
iter: self.0.edges_directed(a, dir),
f: &self.1,
dir,
}
}
}
Expand All @@ -290,6 +292,7 @@ pub struct NodeFilteredEdges<'a, G, I, F: 'a> {
include_source: bool,
iter: I,
f: &'a F,
dir: Direction,
}

impl<'a, G, I, F> Iterator for NodeFilteredEdges<'a, G, I, F>
Expand All @@ -303,8 +306,14 @@ where
if !self.include_source {
None
} else {
let dir = self.dir;
let f = self.f;
self.iter.find(move |&edge| f.include_node(edge.target()))
self.iter.find(move |&edge| {
f.include_node(match dir {
Direction::Outgoing => edge.target(),
Direction::Incoming => edge.source(),
})
})
}
}
fn size_hint(&self) -> (usize, Option<usize>) {
Expand Down
2 changes: 1 addition & 1 deletion tests/graph.rs
Expand Up @@ -1416,7 +1416,7 @@ fn test_node_filtered_iterators_directed() {
};

let gr = make_edge_iterator_graph::<Directed>();
let filter = |node: NodeIndex<u32>| node.index() < 4;
let filter = |node: NodeIndex<u32>| node.index() < 5; // < 5 makes sure there are edges going both ways between included and excluded nodes (e -> g, f -> e)
let filtered = NodeFiltered::from_fn(&gr, filter);

for i in gr.node_indices() {
Expand Down