PEP 218 Re: ANN: set-0.1 module available

Huaiyu Zhu huaiyu at gauss.almadan.ibm.com
Mon May 20 21:59:29 EDT 2002


Erik Max Francis <max at alcyone.com> wrote:
>Huaiyu Zhu wrote:
>
>> The solution appears to be:
>> - Allow mutable and immutable flavors of objects.
>> - Mutable objects are hashed by identity.
>> - Immutable objectas are hashed by content.
>> 
>> No change would then hanve the undesirable effect you described.
>
>But then you can easily have collisions by value between the mutable and
>immutable objects.  That doesn't seem like a very good implementation of
>a set.

There need to be a different equal operator === (read as "always equal")
that is used to compare keys.  For example, the following

a = {1, 2} 
b = a
c = {1, 2} const
d = {1, 2} const

implies a == b == c == d, a === b, c === d, but not a === c.  Therefore "a
in setA" does not imply "c in setA", nor vice versa, even though a==c.  The
following semantical restrictions should apply

id(a) === id(b) implies a === b
a === b implies a==b
a === b implies hash(a) === hash(b)
a == b, a is const, b is const implies a === b

Yes, I know this solution is complicated, but all the proposed solutions
discussed so far map to some subset of this solution.  All the disagreements
were about which subset should be chosen.  I think that every part of this
solution has been proposed by someone.

It is fairly obvious that with mutable objects, equality at an instant in
time is different from equality for all times.  There will never be
concensus about which should be uniquely blessed, because both are useful.

Huaiyu




More information about the Python-list mailing list