[Zope-dev] difference between OOSet and OOTreeSet?
Gary Poster
gary at zope.com
Fri Mar 2 09:39:10 EST 2007
On Mar 2, 2007, at 2:42 AM, Chris Withers wrote:
> Gary Poster wrote:
>>> 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?
>
> Ordered as in sorted, thankfully :-)
:-)
>> If sorted, use BTreeSet (or the keys of a BTree).
>
> As in OOTreeSet, right?
Yes.
>> Even though my assertion is right semantically for "Set", this is
>> a BTreeSet, and I don't see this behavior changing ever.
>
> *phew*
>
>> No, it isn't a sequence, so `reversed` won't work, but `list`
>> will always give you the same order.
>
> Well, you can iterate over it...
>
> Am I right in thinking I can get the reversed semantics I want by
> negating the numeric part of insert?
>
> s = OOTreeSet()
> s.insert(-myvalue)
> s.insert(-someothervalue)
>
> ...I just have to remember to re-negate them when I get 'em out?
Yeah, that would work.
>> "Set" does not match the "doesn't re-store the whole sequence
>> when an item is inserted or removed" requirement.
>
> But OOTreeSet does, right?
Yes.
>> In both cases, IMO you'll want your data to be of homogenous types.
>
> Yep, DateTimes all the way, or if you can't negate them,
> DateTime.timeTime's
Cool. I doubt you can negate the old Zope DateTimes, but who knows
what tricks that class has up its sleeve. ;-)
Gary
More information about the Zope-Dev
mailing list