Closed shoenig closed 1 year ago
I don't think we can ever rely on non-perfect hashing, at least not while using map
under the hood. Unlike some implementations, we have no way of identifying and resolving collisions. First we would need to change the generic parameter type to include an Equal
function (making it incompatible with built-in types), and we would also need to implementing chaining for each of the map
values - storing values with colliding keys.
Maybe it'll be worth revisiting if the Go team figures out how to make ==
vs Equal
less awkward, but until then we should just keep using map
as-is and avoid collisions altogether.
This PR adds HashString(string) and HashParts() helper functions
for computing usable hash values for implementing Hash() functions of
complex struct types.
e.g.
type S struct { A int B string }
func (s *S) Hash() int { return set.HashParts( s.A, set.HashString(B), ) }