-
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
Update the return types of functions #46
base: master
Are you sure you want to change the base?
Conversation
To track the, previusly silently, removed least recenly used keys on insertion or set up capacity.
Thanks for the pull request, and welcome! The contain-rs team is excited to review your changes, and you should hear from @gankro (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. |
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.
Spotted a typo and that triggered a couple of questions.
/me just passing through.
let cap = capacity.saturating_sub(self.len()); | ||
let mut removed_lrus = Vec::with_capacity(cap); | ||
|
||
for _ in capacity..self.len() { | ||
self.remove_lru(); | ||
let removed = self.remove_lru().unwrap(); | ||
removed_lrus.push(removed); | ||
} |
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.
Would using an iterator to create removed_lrus
be as space efficient as your capacity specific vector?
I don't know how the efficiency compares, but I prefer reading the iterator version:
let removed_lrus = capacity..self.len()
.filter_map(|_|: self.remove_lru())
.collect();
impl<K: Eq + Hash, V: PartialEq> PartialEq for Insert<K, V> { | ||
fn eq(&self, other: &Insert<K, V>) -> bool { | ||
self.old_value == other.old_value | ||
&& self.lru_removed == self.lru_removed |
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.
- There is a typo in this line where both sides of the equality reference
self. The latter should be
other`:
&& self.lru_removed == other.lru_removed
- Could we derive this form of PartialEq? It is an element-by-element check for eq, which is the default for
#[derive(PartialEq)]
To track the, previously silent, removed least recently used keys on insertion or map set up capacity.