I'm very unknowledgable about hasing, so sorry if ...
# random
y
I'm very unknowledgable about hasing, so sorry if this is a dumb question. I know that "perfect hashing" is possible when the keys are known in advance (and thus presumably of a fixed size). I have a
MutableMap<MyKey, Any?>
, where
MyKey
is an empty class completely within my control. Is there some way to have "perfect hashing" here by modifying
MyKey
to use some custom hashcodes?
s
What's your goal? A perfect hash on its own won't make a hash table work any better 🤔
e
you can override
hashCode()
, although there's no guarantee that
HashMap
will use the correct number of buckets or the right bucket distribution
☝️ 2
if you defined your own specialized
MutableMap
class you could guarantee that
(unfortunately implementing
AbstractMutableMap
is not straightforward, as the interface requires it to be intertwined with
entries: MutableSet<MutableEntry>
which will likely need to be a custom
AbstractMutableSet
too)