On Fri, Dec 30, 2016 at 10:08 PM, Ethan Furman <et...@stoneleaf.us> wrote:
> So maybe this will work? > > def __hash__(self): > return hash(self.name) * hash(self.nick) * hash(self.color) > > In other words, don't create a new tuple, just use the ones you already > have and toss in a couple maths operations. (and have somebody vet that ;) See the "Simply XORing such results together would not be order-sensitive, and so wouldn't work" from my original post. (Like XOR, multiplication is also commutative.) e.g. Since FrozenOrderedCollection([1, 2]) != FrozenOrderedCollection([2, 1]), we should try to avoid making their hashes equal, or else we increase collisions unnecessarily. More generally, I think the trick is to get an even, chaotic distribution into sys.hash_info.hash_bits out of this hash algorithm, and I think simply multiplying hash values together like this wouldn't do that.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/