Message53362
Logged In: YES
user_id=80475
Weaksets would not be warranted unless the use cases
demonstrated needs for methods unique to sets (intersection,
union, etc). Otherwise, weakdictionaries would suffice and
we could avoid bloating the module.
Also, I'm not sure weaklists are a good idea. First, it is
not clear that the subscription use case can be reliably
implemented with gc as the primary means of unsubscribing --
traditionally, that is done with an explicit unsubscribe()
call issued by the subscriber.
Second, weaklists only have a differential advantage when it
comes to maintaining insertion order. It is not clear that
that feature is really useful. What is clear is that the
approach incurs extra costs for maintaing order and O(n)
removal time.
When order tracking is necessary, there are reasonable
implementations using weakkeydictionaries with the entry
values being a sequence number indicating creation order.
With that data structure, group notification is still simple:
for subscriber in sorted(wkd, key=wkd.__getitem__):
self.notify(subscriber, message)
This approach incurs an O(n log n) sort cost for each group
notify but has only an O(1) deletion cost which is an
improvement over weaklists. The only way I see around the
deletion time issue is to have a weakdoublylinked list which
would allow O(1) deletions, appends, and O(n) iteration.
None of this came up on the referenced newsgroup posting
because there was NO active discussion. IOW, the idea has
not shown any demand and has not been through the basic due
diligence needed to tease out the best approach. I recommend
leaving this as a recipe until we see a battlehardened
implementation, a convincing use case, and some user demand.
|
|
Date |
User |
Action |
Args |
2007-08-23 16:01:48 | admin | link | issue487738 messages |
2007-08-23 16:01:48 | admin | create | |
|