[ZODB-Dev] Re: SVN: ZODB/branches/anguenot-ordering-beforecommitsubscribers/src/transaction/_transaction.py Implement the sort and insert using bisect.insort()

Tim Peters tim at zope.com
Thu Aug 11 15:26:59 EDT 2005


[Florent Guillaume]
> I guess you could simply store and increment then index as an attribute
> of the transaction, yes.

Right!  That's an easy, "obviously correct" way to do it, and is the one I'd
probably do.

Another way is to define a little class to hold a hook's info, and give it a
__cmp__ method that only compares its arguments' order values.  Then using
bisect.insort_right() would guarantee to insert a new instance "at the right
end" of any existing slice of instances sharing the same order value.  That
way a serial number ("index") to break order ties wouldn't be needed at all.
So that's attractive too, but would be a little heavier to code.

Provided you understand the bisect module first, what's _hard_ is to do it
in a wrong way <0.9 wink>.



More information about the ZODB-Dev mailing list