[Python-Dev] Hashable memoryviews

Stefan Krah stefan at bytereef.org
Sun Nov 13 14:13:19 CET 2011


Antoine Pitrou <solipsis at pitrou.net> wrote:
> Stefan Krah <stefan at bytereef.org> wrote:
> > I think they necessarily have to use the same hash, since:
> > 
> > exporter = m1 ==> hash(exporter) = hash(m1)
> > m1 = m2 ==> hash(m1) = hash(m2)
> > 
> > Am I missing something?
> 
> The hash must simply be calculated using the same algorithm (which
> can even be shared as a subroutine). It's already the case for more
> complicated types:
> 
> >>> hash(1) == hash(1.0) == hash(Decimal(1)) == hash(Fraction(1))
> True

Yes, but we control those types. I was thinking more about third-party
exporters. Then again, it would be possible to publish the unified
hash function as part of the PEP.

Perhaps we could simply use:

    PyBuffer_Hash = hash(obj.tobytes())

Since tobytes() follows the logical structure, it should work for
non-contiguous and multidimensional arrays as well.


Stefan Krah




More information about the Python-Dev mailing list