-
Notifications
You must be signed in to change notification settings - Fork 21
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
hashCode for NumericRange is computed by evaluating all values #12922
Comments
@scala/collections |
This comment was marked as duplicate.
This comment was marked as duplicate.
Personally, I see nothing terrible about a library ticket on the dotty side. scala/scala3#19217 Since this repo is not scala/scala, the ticket has no natural home on github. Also, is it not possible to transfer tickets? And what would be the consequence of opening scala/scala issues for future maintenance tickets? The template for scala/scala tickets would have a title of the form |
I'm not sure this is feasible. Collections who are computing their hashcodes actually check whether they're traversing a range, and if they are, they throw away the sequence-computed hashcode and pick the one that matches But to do that for every type supported by So there isn't any shortcut that will ensure that You could do a shortcut to And since you are so obligated, it's not totally clear to me that it's worth fixing the other stuff. |
Please note this PR on NumericRange, where I attempt to prevent the need of iterating over the whole range for the What is especially interesting in regard to this issue is my finding that NumericRange allows you to make a range of more than A better longterm solution might be to simply accept that this class really doesn't support more than |
I'm going to provisionally close this as "not planned", since @Ichoran's argument that we can't shortcut this seems persuasive to me. Happy to reopen if someone can convincingly argue otherwise. |
Reproduction steps
Scala version: 2.13.10, but the problem is also present in other versions
Problem
The hash code of a numeric range should be calculated properly. It seems that
NumericRange
usesMurmurHash3.indexedSeqHash
which evaluates all values in the range to compute the hash code.Additionally, even when the range is small enough, the hash code computation is ineffective and may affect the code performance e.g. when a
Set[NumericRange[Long]]
is used.The text was updated successfully, but these errors were encountered: