Skip to content

Conversation

@Kerollmops
Copy link

To track the, previously silent, removed least recently used keys on insertion or map set up capacity.

To track the, previusly silently, removed least recenly used keys on insertion or set up capacity.
@FlashCat
Copy link
Contributor

FlashCat commented Feb 3, 2018

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.

Copy link

@spazm spazm left a 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.

Comment on lines +251 to 257
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);
}
Copy link

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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
  1. Could we derive this form of PartialEq? It is an element-by-element check for eq, which is the default for #[derive(PartialEq)]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants