This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author loewis
Recipients Arfrever, christian.heimes, georg.brandl, loewis, mark.dickinson, meador.inge, ncoghlan, pitrou, skrah, vstinner
Date 2012-08-29.19:33:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <503E6E97.3080101@v.loewis.de>
In-reply-to <1346266979.3344.1.camel@localhost.localdomain>
Content
Am 29.08.12 21:06, schrieb Antoine Pitrou:
>> So what specific hash algorithm do you propose?
>
> The current algorithm works well in conjunction with bytes objects.

That's about the only type if works for.

>> My claim is that any hash definition for memoryviews will have a
>> *fundamental* flaw, failing to provide the basic property
>> that A==B must imply hash(A)==hash(B), making it actually work
>> incorrectly
>
> Why is there such a fundamental flaw?

The current algorithm is flawed as described in Stefan's original
message: two objects compare equal, yet hash different. That means
that if you use them as dictionary keys, you may end up with two
different values for the "same" key, depending on the size of the
dictionary (as the modulo operation in the dictionary still may
map the different hashes to the same dictionary slot).

In general, since memoryview(obj)==obj, it would be necessary that
hash(memoryview(obj))==hash(obj). However, since memoryview cannot
know what hashing algorithm obj uses, it cannot compute the hash
value with the same algorithm.

IOW, hashing is mutually exclusive with comparison with the
underlying object, unless you know what the hash algorithm
of the underlying object is.

So restricting tp_hash to memoryview objects where the underlying
object is the bytes type would work.
History
Date User Action Args
2012-08-29 19:33:48loewissetrecipients: + loewis, georg.brandl, mark.dickinson, ncoghlan, pitrou, vstinner, christian.heimes, Arfrever, skrah, meador.inge
2012-08-29 19:33:47loewislinkissue15814 messages
2012-08-29 19:33:45loewiscreate