dave08
01/30/2023, 4:40 PMString
Int
and a data class, how can I make a unique hash key out of all three (for a key in a cache map) without any extra allocations? (I know I could always put them all in a data class and use that as a key or just use it's hashCode()... but I don't need that extra class...)Sam
01/30/2023, 4:44 PMObjects.hash(…)
, which takes a vararg.dave08
01/30/2023, 4:45 PMSam
01/30/2023, 4:46 PMdave08
01/30/2023, 4:50 PMThis answer probably isn’t useful, since for a map key you need a full equality check, not just a hashCodeIt's just a cache layer over an api to avoid requesting the same response for the same input params... so I don't really care of the content of the key, just that there shouldn't be any collisions, and effieciency of retreival.
not that I would normally recommend thoseSo what would you recommend?
Sam
01/30/2023, 4:51 PMTriple
because you lose the ability to give names to the three values. I would usually just go ahead and make a data class, even if the use case seems trivial.dave08
01/30/2023, 4:53 PMSam
01/30/2023, 4:55 PMTriple
is currently implemented as a data class, so the hashCode behaviour is probably identical.dave08
01/30/2023, 4:56 PMSam
01/30/2023, 4:59 PMmkrussel
01/30/2023, 5:00 PM