From: Nasir Khan Date: 2007-06-11T10:08:19+09:00 Subject: Re: bug in facets 1.8.54 ------=_Part_102890_18892848.1181524099865 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Thanks Olivier. IMHO def initialize(compareProc=3Dlambda{|x,y| x>y}, elements=3Dnil) could have preserved backwards compatibility for PQueue users and also preserved semantics of passing the comparator as an argument rather than a block. Shall work around for now. Thanks Nasir On 6/10/07, Olivier Renaud wrote: > > Le samedi 09 juin 2007 22:14, Nasir Khan a =E9crit: > > Ah! pqueue.rb was changed to be backward incompatible from facets > > 1.8.51 -> 1.8.54 > > > > > > # 1.8.51 > > def initialize(compareProc=3Dlambda{|x,y| x>y}) > > # By default, retrieves maximal elements first. > > @qarray=3D[nil]; @size=3D0; @gt=3DcompareProc; make_legal > > end > > > > > > # 1.8.54 > > def initialize(elements=3Dnil, &block) # :yields: a, b > > @qarray =3D [nil] > > @size =3D 0 > > @gt =3D block || lambda {|a,b| a > b} > > replace(elements) if elements > > end > > > > > > Is there a way to load 1.8.51 version of one file (in this case > > pqueue.rb) while use rest of the facets gem 1.8.54? > > The other option is to monkey patch :-( > > Any other option? > > > > - nasir > > > > Hi, > > Yes you are right, pqueue was rewritten and the api changed a lot. In > Facets, > there was two different classes for the same purpose, PQueue and Heap, > which > both provided a heap based priority queue. The latter was broken, althoug= h > it > had functionalities that pqueue lacked. > > So, I merged both classes into one full-featured class, with a different > API, > closer to the Array one and more ruby-like to me. I submitted it, and as = I > based my work on pqueue, it replaced the previous version of the class, > and > Heap was removed. > > Here is the notes I transmitted to Trans, who maintains Facets : > > * Initialization can take both initial values and comparison block, both > optionnaly. Whereas the original PQueue take only a block, and Heap take > only > the initial values and needs to be subclassed in order to implement the > comparison > * Every methods which take an array as a parameter (initialize, push_all, > replace) can now take any object that responds to #to_a, and are optimize= d > in > the case where the given object is a PQueue itself. > * Creating a queue from scratch (with #initialize or with #replace) is > faster > than for the original PQueue, by adapting the #heapify method from Heap. > * Added consistent methods #inspect, #=3D=3D, #initialize_copy. > * Methods are documented and unit-tested. > > I dropped some methods from both original classes : > * PQueue#make_legal, useless since the PQueue is now always legal > * PQueue#replace_top_low, which I can't figure out the purpose :) > * PQueue#each_with_index, already provided by Enumerator > * Heap#sort_internal, was like an inplace-sort, but it destroyed the > PQueue. > > Actually, I didn't know it was already commited :) > If you used only push, pop, clear and empty? in your client code, then th= e > only api change is for the instanciation method, which doesn't take a Pro= c > object as an argument, but a block. > > I see no other solution than monkey patching, if you really don't want to > modify your client code. > > Regards > > -- > Olivier Renaud > > ------=_Part_102890_18892848.1181524099865--