Update the return types of functions#46
Update the return types of functions#46Kerollmops wants to merge 2 commits intocontain-rs:masterfrom Kerollmops:master
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. |
spazm
left a comment
There was a problem hiding this comment.
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.
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.
- There is a typo in this line where both sides of the equality reference
self. The latter should beother`:
&& 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.