R
Aahz said:That is *sick* and perverted.
I'm not sure why.
Would it be less sick if it had been called "UniqueList" ?
The doubly-linked list part is what's sick and perverted.
The double-linked list part could be done with weakrefs and
perhaps Aahz would relax a bit.
Raymond said:[Aahz]The doubly-linked list part is what's sick and perverted.The doubly-linked list part is what gives it big-oh running
times the same as regular sets. If the underlying sequence
is stored as a list, then deletion goes from O(1) to O(n).
If the insertion times are recorded in a dictionary, then
the insertion order has to be sorted prior to iteration
which makes iteration go from O(n) to O(n log n).
The double-linked list part could be done with weakrefs and
perhaps Aahz would relax a bit.
--Scott David Daniels
(e-mail address removed)
Raymond said:[Aahz]The doubly-linked list part is what's sick and perverted.
The doubly-linked list part is what gives it big-oh running times the
same as regular sets. If the underlying sequence is stored as a list,
then deletion goes from O(1) to O(n). If the insertion times are
recorded in a dictionary, then the insertion order has to be sorted
prior to iteration which makes iteration go from O(n) to O(n log n).
The double-linked list part could be done with weakrefs and perhaps Aahz
would relax a bit.
Steven said:The double-linked list part could be done with weakrefs and perhaps AahzRaymond said:[Aahz]
The doubly-linked list part is what's sick and perverted.
The doubly-linked list part is what gives it big-oh running times the
same as regular sets. If the underlying sequence is stored as a list,
then deletion goes from O(1) to O(n). If the insertion times are
recorded in a dictionary, then the insertion order has to be sorted
prior to iteration which makes iteration go from O(n) to O(n log n).
would relax a bit.
I'm not sure whether Aahz's description is meant to be taken seriously,
or if there is a smiley hidden in his post. After all, doubly-linked
lists are a standard building block in data structure design.
But assuming it is meant as a serious criticism, I'm not sure that I like
the idea of using weakrefs. I think it is a feature, not a bug, that
sets, lists and dicts keep a reference to the items in them. I think it
would be bizarre if putting an item into an OrderSet meant that you
needed to put it somewhere else as well to prevent it being garbage
collected.
Or have I misunderstood the consequences of using weakrefs?
I think the idea was 2 weakrefs and 1 normal ref instead of 3 normal refs.
Raymond said:Right. Here's a link to a weakref version (though I think the
previous __del__ version also does the trick):
http://code.activestate.com/recipes/576696/
(2) Why, oh why, do people feel so comforted adding double_underscores
to data structures? If I want to inherit from your mapping in order
to log the attempts to discard a key not actually in the set, I
have to either us the nasty name mangling to get at self.__map, or
name my subclass OrderedSet and take advantage of a not-guaranteed
name mangling. What on earth makes you unwilling to go with "_map"
and credit your code's consumers with a bit of common sense?
Sorry, this latter rant has been building up for a while (spurred on by
a sojourn into the unittest code where they have the private disease in
spades.
Raymond said:[Aahz]
The doubly-linked list part is what's sick and perverted.
The doubly-linked list part is what gives it big-oh running times the
same as regular sets. If the underlying sequence is stored as a list,
then deletion goes from O(1) to O(n). If the insertion times are
recorded in a dictionary, then the insertion order has to be sorted
prior to iteration which makes iteration go from O(n) to O(n log n).
The double-linked list part could be done with weakrefs and perhaps Aahz
would relax a bit.
I'm not sure whether Aahz's description is meant to be taken seriously,
or if there is a smiley hidden in his post. After all, doubly-linked
lists are a standard building block in data structure design.
En Thu, 26 Mar 2009 12:20:17 -0300, Scott David Daniels
... __slots__ = ["prev", "next", "this"]
... def __init__(self, prev, next, this):
... self.prev = prev
... self.next = next
... self.this = this
[...]
So the Node class actually takes less memory 38 Mbytes vs 53 Mbytes
for the list.
I really like the Ordered Set class(I've been thinking about one ever
since ordered dict hit the std lib), is there any argument against
adding one to the collections module? I'd be willing to write a PEP
up for it.
Suppose the implementation would use a circular linked list. Then the
iteration could start from any point, the thing is symmetric after
all. But this would also mean we could add items to the left of that
new starting point, since that would now be the 'end' of the circle.
This is something different from merely remembering insertion order.
How do you feel about that?
My inclination would be to more or less *just* have it implement the
set API, the way ordered dict does in 2.7/3.1.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.