mò )á¸Ec@s7dZdklZdklZdfd„ƒYZdS(sÌNBest An NBest object remembers the N best-scoring items ever passed to its .add(item, score) method. If .add() is called M times, the worst-case number of comparisons performed overall is M * log2(N). (sbisect(sINBesttNBestcBsMtZeZd„Zd„Zd„Zd„Zd„Zd„Z d„Z RS(NcCs<|djotdƒ‚n||_g|_g|_dS(s=Build an NBest object to remember the N best-scoring objects.is#NBest() argument must be at least 1N(tNt ValueErrortselft _capacityt_scorest_items(RR((t9/data/zmath/zope/lib/python/Products/ZCTextIndex/NBest.pyt__init__s    cCs t|iƒS(N(tlenRR(R((Rt__len__)scCs|iS(N(RR(R((Rtcapacity,scCs|i||fgƒdS(N(Rtaddmanytitemtscore(RR R((Rtadd/sc CsÛ|i|i|i}}}t|ƒ}x‘|D]‰\}}||jo||djoq0nt ||ƒ}|i||ƒ|i||ƒ||jo|d=|d=q0|d7}q0W|t|ƒjpt‚dS(Nii(RRRRtscorestitemsR R tntsequenceR RtbisecttitinserttAssertionError( RRR RRRR RR((RR 2s   cCs#t|i|iƒ}|iƒ|S(N(tzipRRRtresulttreverse(RR((RtgetbestDs cCs@|io&|iidƒ|iidƒfSntdƒ‚dS(Nis+pop_smallest() called on empty NBest object(RRRtpopt IndexError(R((Rt pop_smallestIs &( t__name__t __module__tINBestt__implements__RR R RR RR(((RRs     N(t__doc__RtProducts.ZCTextIndex.INBestR!R(RR!R((Rt?s