Re: set of sets
- From: Paolo Veronelli <paolo_veronelli@xxxxxxxx>
- Date: Thu, 11 Aug 2005 16:27:39 +0200
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 calling hash(s).
Why don't you just use "frozenset"?
And mostly with sets remove operation expense should be sublinear or am I wrong? Is this fast as with lists? Obviously if I use the ids as hash value nothing is guaranted about the objects contents to be unique but I don't care. My work is a self organizing net,in which the nodes keep a structure to link other nodes.As the nature of the net,the links are moved frequently so remove and add operations and contains query should be optimized. Why objects need to be hashable for this? Isn't __hash__ there to solve the problem? PS Looks like the problem is not present in class sets.Set
___________________________________ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it
.
- Follow-Ups:
- Re: set of sets
- From: Matteo Dell'Amico
- Re: set of sets
- References:
- set of sets
- From: Paolino
- Re: set of sets
- From: Matteo Dell'Amico
- set of sets
- Prev by Date: Re: what's the exactly newsgroup url of python-list?
- Next by Date: net view /domain
- Previous by thread: Re: set of sets
- Next by thread: Re: set of sets
- Index(es):
Relevant Pages
|