[ZPT] Re: re# IMPORTANT NOTE## Getting the length of a BTree, TreeSet,or output of keys,# values, or items of same is expensive. If you needto get the# length, you need to maintain this separately.#Pleasemake "total" lazy!
Casey Duncan
casey@zope.com
Sat, 16 Mar 2002 14:58:52 -0700
ZCatalog results can be just as bad. Doing a len on a Lazy sequence can
sometimes result in touching every item.
Just make total a method.
Also, why are you calling this total? I think that name implies an
aggregate sum, not a length. Perhaps it should be called
"sequence-length" 8*)
-Casey
Chris Withers wrote:
> Steve Alexander wrote:
>
>># IMPORTANT NOTE
>>#
>># Getting the length of a BTree, TreeSet, or output of keys,
>># values, or items of same is expensive. If you need to get the
>># length, you need to maintain this separately.
>>
>
> But why would the length of a ZCatalog results set need to be calculated in this way?
>
> cheers,
>
> Chris
>
> PS: If it does need to calculate it in this way, I think that's a bug in the BTrees
> implementation. The users shouldn't have to care about how the length is stored or
> computed, the BTrees internally should keep a seperate counter ifthat's what they need to
> do, then it can be kept in synch in a much tigher loop..
>
> _______________________________________________
> ZPT mailing list
> ZPT@zope.org
> http://lists.zope.org/mailman/listinfo/zpt
>
>