Paolo Veronelli wrote:
> Yes this is really strange.
>
> from sets import Set
> class H(Set):
> def __hash__(self):
> return id(self)
>
> s=H()
> f=set() #or f=Set()
>
> f.add(s)
> f.remove(s)
>
> No errors.
>
> So we had a working implementation of sets in the library an put a
> broken
Paolo Veronelli wrote:
> And mostly with sets remove operation expense should be sublinear or am
> I wrong?
> Is this fast as with lists?
It's faster then with lists... in sets, as with dicts, remove is on
average O(1).
> Obviously if I use the ids as hash value nothing is guaranted about the
>
Paolino wrote:
> I thought rewriting __hash__ should be enough to avoid mutables problem but:
>
> class H(set):
>def __hash__(self)
> return id(self)
>
> s=H()
>
> f=set()
>
> f.add(s)
> f.remove(s)
>
> the add succeeds
> the remove fails eventually not calling hash(s).
>
Yes this i
Paolino wrote:
> Matteo Dell'Amico wrote:
>>Why don't you just use "frozenset"?
>
> This is what I'm doing, but the problem remains IMO.
> Anyway with frozenset I have to override __new__ instead of __init__ to
> make the initialization which is an operation not described in the
> frozenset do
Matteo Dell'Amico wrote:
> Paolino wrote:
>
>>I thought rewriting __hash__ should be enough to avoid mutables problem
>>but:
>>
>>class H(set):
>> def __hash__(self)
>>return id(self)
>>
>>s=H()
>>
>>f=set()
>>
>>f.add(s)
>>f.remove(s)
>>
>>the add succeeds
>>the remove fails eventually not
Matteo Dell'Amico wrote:
> Paolino wrote:
>
>>I thought rewriting __hash__ should be enough to avoid mutables problem
>>but:
>>
>>class H(set):
>> def __hash__(self)
>>return id(self)
>>
>>s=H()
>>
>>f=set()
>>
>>f.add(s)
>>f.remove(s)
>>
>>the add succeeds
>>the remove fails eventually not
Paolino wrote:
> I thought rewriting __hash__ should be enough to avoid mutables problem
> but:
>
> class H(set):
> def __hash__(self)
> return id(self)
>
> s=H()
>
> f=set()
>
> f.add(s)
> f.remove(s)
>
> the add succeeds
> the remove fails eventually not calling hash(s).
Why don't yo
I thought rewriting __hash__ should be enough to avoid mutables problem but:
class H(set):
def __hash__(self)
return id(self)
s=H()
f=set()
f.add(s)
f.remove(s)
the add succeeds
the remove fails eventually not calling hash(s).
Thanks for help
Paolino