A suggestion

Hannes Hirzel hirzel at spw.unizh.ch
Wed Mar 13 16:38:06 UTC 2002


On Wed, 13 Mar 2002, Richard A. O'Keefe wrote:

> Henrik Gedenryd <h.gedenryd at open.ac.uk> wrote:
> 	Avoiding the discussion of sorting performance, you can provide a sort block
> 	to SortedCollections, which then could be something like
> 	
> 	[:a :b |
> 	    (1 to: (a size min: b size)) allSatisfy: [:i |
> 	        (a at: i) <= (b at: i)]]
> 	
> 	This avoids writing an extra method.
> 	
> Aside from the fact that the code shown isn't even close to working
> (what I need is lexicographic order, which this isn't, and
>  what a sortblock must provide is a total order over the elements in
>  the collection, which this doesn't)
> it's the same amount of code whether it's in a block or a method.
> 
> The difference is that if it's in a method, it can be used elsewhere.
> 
> The other difference, of course, is that to implement lexicographic
> order, it is convenient to use "^" to exit as soon as a difference is
> found.  If I stick that in a block, it will exit the wrong chunk of
> code.  The code could be twisted in various ways (some of which I _have_
> considered) to avoid this, but I think it is clearest as I wrote it.
> 
> If we are allowed to add arrays (and we are), why not compare them?
> And if we compare them, is lexicographic order the most suitable?
> (There are other orders which are also compatible with =, such as
>  - first compare the lengths,
>  - then compare the elements ONLY if the lengths are the same.
>  This is almost always faster, and has some nice properties.
>  It's just not what Squeak uses for Strings.)
> 
> 
> 

Richard,

Your argument looks convincing. Go ahead and publish your [ENH]ancement!

Hannes Hirzel 




More information about the Squeak-dev mailing list