-
Notifications
You must be signed in to change notification settings - Fork 384
Retain for stable graph #127
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
Conversation
Hi, to be frank with you here I'd expect the PR to explain the thoughts behind the change. I disagree with adding a method that does not have the same signature as the corresponding one on Graph. |
Now actually consistent with Graph::retain_nodes
It's my first public pull-request so I might do some things the wrong way. As for actual content: I see your point. And considering this signature corresponds to the std::vec::Vec signature this should probably be reverted. I'll remove the output vector. if you're curious for my thoughts: I'd consider the Vec and Graph signature insufficient. However this needs to be measured against other concerns (which I did not do!):
|
StableGraph and Graph should have the same interface where it's possible. It may be insufficient but having the interfaces mismatch only means it's a halfway done API transition: one or the other will need to change to match, otherwise the library is a mess. There is no trade off here IMO; it's about fixing the signature or starting to plan the name and signature of the new API. From your message it sounds like there is no pressing use case behind the choice to return a Vec, and then I think the choice of design is simple (don't return the Vec). (We have the benefit that removing nodes in sequence is not quadratic with the stable graph, since nodes don't shift. Regular Graph can achieve this too by removing them in reverse order, which is how Graph::retain_nodes is implemented.) |
To be sure: the tests fail because of an update to nightly. I think this is a compiler bug regarding scope. I opened an issue rust-lang/rust#40235
|
src/stable_graph.rs
Outdated
pub fn retain_nodes<F>(&mut self, mut f: F) where F: FnMut(Frozen<Self>, NodeIndex<Ix>) -> bool { | ||
for i in 0..self.g.node_count() { | ||
let ix = node_index(i); | ||
if !f(Frozen(self), ix) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah this should check first if ix
is a node in the graph.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh and the upper bound is not node_count
but the upper bound count.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The node count is correct: the count of the unstable subgraph is used.
Added the check. The users should indeed not do this manually.
Thank you! I'm sorry for the delay. I'll try out the squash merge button, then I don't have to ask you to do the squash.. See you on the other side.. |
Looks like it worked! |
Lets try this again.