Closed tr7zw closed 4 years ago
Would it not be a clearer way of storing int arrays to use an ObjectOpenCustomHashSet
with the int array hashing strategy provided in IntArrays#HASH_STRATEGY
?
This "fixed" implementation is broken in a different way, as it's using an int->obj hash table where the integer key is the hash code of the object. These 32-bit hash codes can have collisions and will cause other issues.
The best solution is to just use a collection type with a custom hash/equals strategy as Chocohead points out above.
Oh you're right. At first I was looking into ObjectOpenCustomHashSet
, but I didn't know about IntArrays.HASH_STRATEGY
. I see you also fixed it in FastImmutableTableCache
👍
Arrays can't be compared using .hashcode()/equals(), so the ObjectOpenHashSet will create an entry for each array. Now using a Map<int, int[]> and the correct Arrays.hashCode(...) to compute the hashcode.