-
Notifications
You must be signed in to change notification settings - Fork 36
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
perf: precompute intersections (2x speedup) #37
Conversation
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.
Looks good to me
Woops sorry for closing this one. I was cleaning my unused branches and didn't realized the last commit was still mine here. I thought @Eh2406 would have done a new commit. |
I'll review in the morning. |
3ee2333
to
37dc249
Compare
@@ -80,8 +80,7 @@ impl<P: Package, V: Version> PartialSolution<P, V> { | |||
.rposition(|(l, _)| *l == decision_level) | |||
.unwrap_or(self.history.len() - 1); | |||
*self = Self::from_assignments( | |||
self.history | |||
.to_owned() | |||
std::mem::take(&mut self.history) |
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.
This must be working as intended since tests pass, but I would like to ask for my own understanding.
std::mem::take
replaces self.history
with a default value, i.e. empty Vec
in this case. Before the change the history was retained.
Why doing this is correct in this case?
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.
Because we are building a new self and its history and assigning it to *self
.
old code:
let copy = self.history.to_owned();
let new_self = Self::from_assignments(copy);
*self = new_self;
Note how no one uses the self.history
after the copy. It is just replaced as part of the last line.
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.
Didn't see that, thank you for the explanation!
@aleksator why do we say |
The rule of thumb in my understanding is yes. Let me try to google where I got that from... The search term I'm going to use is First link from Duckduckgo is ambiguous, just saying that it can be either, but usually singular. It says plural is for nouns that usually refer to people or are mostly used in plural form; Second link defines a proper name for this which could be used for later searches: It is rather unhelpful 🙄, but that's what I generally use as a basis for my changes as well. If it sounds way off when I read it, it probably should be changed. If both ways sound clear or both sound a bit weird to my ear, then I leave it as is. Disclaimer: I'm not a native speaker myself, although everything that could be done using English I do in English for the past decade or so. That only leaves verbal communication with surrounding people who don't speak English that has to be done in my native language, so I often find myself having to just drop in English words in my speech rather than pause trying to remember what the translation is. 😅 |
An example of a function I didn't rename and why: Here if we rename it to While |
By the way, I am a native speaker, but my spelling and grammar are atrocious. So I deeply appreciate your correction of any mistakes you find. |
Thank you! I hope I'm not too pedantic with this stuff 😄 |
This is a cleaned up version of @mpizenberg's work in #33 (comment)