[Zope-dev] difference between OOSet and OOTreeSet?
Gary Poster
gary at zope.com
Thu Mar 1 16:43:35 EST 2007
On Mar 1, 2007, at 3:18 PM, Chris Withers wrote:
> Gary Poster wrote:
>>> Traceback (most recent call last):
>>> File "<stdin>", line 1, in ?
>>> TypeError: argument to reversed() must be a sequence
>> The fact that this works for the OOSet is an implementation accident.
>> As discussed elsewhere in this thread, sets are not sequences.
>> The fact that the elements are ordered is an implementation detail
>> (although given that these sets are essentially the keys of a
>> BTree, it's unsurprising that they are).
>> You could argue that reversed(OOSet((1,2,3))) should raise an
>> exception. IMO, why bother.
>
> *grunt*
>
> Okay, so I want a persistent, ordered sequence which is quick to
> find items in and which doesn't re-store the whole sequence when an
> item is inserted or removed.
>
> What should I be using?
Ordered, as in sorted? Or ordered, as in user-determined order?
If sorted, use BTreeSet (or the keys of a BTree). Even though my
assertion is right semantically for "Set", this is a BTreeSet, and I
don't see this behavior changing ever. No, it isn't a sequence, so
`reversed` won't work, but `list` will always give you the same
order. "Set" does not match the "doesn't re-store the whole
sequence when an item is inserted or removed" requirement.
If user-determined (like a list) then you are currently out of luck.
I actually have a implementation of this (which I think is cool) with
some tests, but I regard it as experimental and am refactoring it in
my spare (ha) time. (I would not mind you looking at what I have,
but I don't particularly recommend it yet for production, so I expect
it is useless to you.)
In both cases, IMO you'll want your data to be of homogenous types.
Gary
More information about the Zope-Dev
mailing list