You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Variation on the above:
Make different types never be equal in the hashing context. How to determine whether types are "same" or "different"? Again, a few suggestions:
It's the exact same type
The types have the same hash method (same type or inherited).
+1 for ruby-like solution. But it's fine now, C# and Java also make the hash of 0 and 0.0 the same.
IMO, Crystal gets everything to be objects, so the hash should be different when these two items having different type even their data is the same in the memory at least, so 0's hash will never equals to 0.0's, cause their types are not the same at all.
Without diving in to the problem, at a glance I'd say it's not a problem with hashing (duplicates are expected - it's not meant to be perfect hashing, just fast and distribute over buckets and similar uses).
The problem with the hash-map must be because 0 == 0.0 - so this instead puts some more fuel on: [edited...]#567 (comment) (don't allow float <=> int promotions) implementation of comparison between ints and floats. But this was a shot from the hip... Just comparing floats to "should be the same" floats itself is inexact business...
First, the immediate problem caused by this fact:
Because:
(there don't seem to be any other such "hash collisions" other than 0 but my search wasn't exhaustive, and this is still dangerous).
In case this wasn't clear, the problem is the definition of hashes is violated – equal values must have equal hashes.
I see a few general approaches to solving this:
Introduce a "hash equality" concept and explicitly mark Ints and Floats to be not equal in the hashing context.
(The example above would have 4 pairs in the end)
Make different types never be equal in the hashing context. How to determine whether types are "same" or "different"? Again, a few suggestions:
Set up the hashing functions in a way that Ints and Floats have the same hash.
(The example above would have 2 pairs in the end)
Theoretically we could take their algorithm but not sure about licensing.
To elaborate what Python does:
The text was updated successfully, but these errors were encountered: