That is not correct and will not work - what the op is talking about is if K
collides - so this is only a single K - so map[K][]struct{K;V} will only ever
have one element in the array…
> On Jun 25, 2025, at 12:33 PM, 'Axel Wagner' via golang-nuts
> <[email protected]> wrote:
>
> There are ∞ many possible hashable Go values (in particular, all strings) and
> 2^64 uint64, so yes, there is a possibility of collision.
> How big that risk is depends on how many values you have and what the damage
> is, if a collision happens.
> Wikipedia has a nifty table:
> https://en.wikipedia.org/wiki/Birthday_attack#Mathematics
> There, you can see that if you have a 64 bit hash and have, say 190K
> elements, the probability of a random collision is roughly 10^-9 (so pretty
> small, but not completely impossible).
> If a collision is truly problematic, a simple fix would be to use a
> map[K][]struct{K;V}. That way, if there *is* a collision on the hash, you
> store all the colliding values and can walk the slice to find the right one.
> As collisions should be rare, that should be an uncommon cost to pay.
>
> On Wed, 25 Jun 2025 at 17:26, Pierre Durand <[email protected]
> <mailto:[email protected]>> wrote:
>> Is it safe to use the result of a hash/maphash (uint64) as a map key.
>> Is there a risk of collision ? (different inputs generate the same hash)
>>
>> Thank you
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected]
>> <mailto:[email protected]>.
>> To view this discussion visit
>> https://groups.google.com/d/msgid/golang-nuts/c8076635-5311-4e17-81c7-4907857df145n%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/golang-nuts/c8076635-5311-4e17-81c7-4907857df145n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected]
> <mailto:[email protected]>.
> To view this discussion visit
> https://groups.google.com/d/msgid/golang-nuts/CAEkBMfH6WzHLzoz%3DMe30MamY6th8miTqLFd4_LT_kJ%2BLB2%2B9gg%40mail.gmail.com
>
> <https://groups.google.com/d/msgid/golang-nuts/CAEkBMfH6WzHLzoz%3DMe30MamY6th8miTqLFd4_LT_kJ%2BLB2%2B9gg%40mail.gmail.com?utm_medium=email&utm_source=footer>.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/golang-nuts/429F5804-ADC8-4E5A-AE30-706C45D4C4B0%40ix.netcom.com.