Skip to content
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

Add SummingWithHitsCache class to also track key hits. #410

Merged
merged 4 commits into from Feb 6, 2015

Conversation

reconditesea
Copy link
Contributor

No description provided.

extends SummingCache[K, V](capacity)(sgv) {

def putWithHits(m: Map[K, V]): (Int, Option[Map[K, V]]) = {
val keyHits = m.keys.filter(cache.get(_).isDefined).size
Copy link
Collaborator

Choose a reason for hiding this comment

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

m.keys.count(cache.contains)

@johnynek
Copy link
Collaborator

johnynek commented Feb 5, 2015

Let's add some tests, but otherwise this looks good. What do you think about the private constructor? That was unusual before and caused a problem here. Should we just make the constructor public? What do we gain from private constructor? (I did it before, but I think it was a mistake now).

@reconditesea
Copy link
Contributor Author

I actually don't know the reason of why it's private in the first place. So I just changed it to protected to make this work. If you feel the private accessor is not needed any more, I think let's go ahead change it to public.

@reconditesea
Copy link
Contributor Author

@johnynek Added several tests for it.

/**
* A SummingCache that also tracks the number of key hits
*/
class SummingWithHitsCache[K, V] private (capacity: Int)(implicit sgv: Semigroup[V])
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's make this one public too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.
Just out of curiosity, what's the original reason to make the constructor private?

@johnynek
Copy link
Collaborator

johnynek commented Feb 6, 2015

after we fix the public issue, LGTM.

johnynek added a commit that referenced this pull request Feb 6, 2015
Add SummingWithHitsCache class to also track key hits.
@johnynek johnynek merged commit 8be81d8 into develop Feb 6, 2015
@johnynek johnynek deleted the klin_summing_hit_cache branch February 6, 2015 23:24
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.

None yet

2 participants