[Python-Dev] Hashable memoryviews (original) (raw)

Stefan Behnel stefan_ml at behnel.de
Sun Nov 13 13:16:59 CET 2011


Stefan Krah, 13.11.2011 13:05:

Nick Coghlan wrote:

With slices or the new casts (See: http://bugs.python.org/issue5231, implemented in http://hg.python.org/features/pep-3118#memoryview ), it is possible to have different hashes for equal objects:

Note that Antoine isn't suggesting that the underlying hash be used as the memoryview's hash (that would be calculated according to the same rules as the equality comparison). Instead, the ability to hash the underlying object would just gate whether or not you could hash the memoryview at all. I think they necessarily have to use the same hash, since: exporter = m1 ==> hash(exporter) = hash(m1) m1 = m2 ==> hash(m1) = hash(m2)

You can't expect the memoryview() to magically know what the underlying hash function is. The only guarantee you get is that iff two memoryview instances are looking at the same (subset of) data from two hashable objects (or the same object), you will get the same hash value for both. It may or may not correspond with the hash value that the buffer exporting objects would give you.

Stefan



More information about the Python-Dev mailing list