order independent hash?
Hrvoje Niksic
hniksic at xemacs.org
Sun Dec 4 08:55:32 EST 2011
Terry Reedy <tjreedy at udel.edu> writes:
>> [Hashing is] pretty much mandated because of the __hash__ protocol.
>
> Lib Ref 4.8. Mapping Types — dict
> "A mapping object maps hashable values to arbitrary objects."
>
> This does not say that the mapping has to *use* the hash value ;-).
> Even if it does, it could use a tree structure instead of a hash
> table.
An arbitrary mapping doesn't, but reference to the hash protocol was in
the context of implementation constraints for dicts themselves (my
response quotes the relevant part of Chris's message). If a Python
implementation tried to implement dict as a tree, instances of classes
that define only __eq__ and __hash__ would not be correctly inserted in
such a dict. This would be a major source of incompatibility with
Python code, both in the standard library and at large.
More information about the Python-list
mailing list