[Q]uestions regarding collections

Wim Boot Wim.Boot at bwise.nl
Mon Aug 20 07:49:46 UTC 2001


Jon Hylands wrote:

>> It would be irrelevant if the collection was ascending or descending.  
>> You can just use sortBlock value: x value: y.  If true, go one way, if 
>> false go to another.  You don't need to know anything about what the 
>> objects respond to (I've use sortBlocks like [:a :b| a x > b x] and [:a 
>> :b|a date < b date]), because the sortBlock can tell you.

>Yeah, I'm looking at #indexForInserting: which does exactly that kind of
>binary search.
>
>Its funny, I don't think any of the major Smalltalk implementations use a
>binary search for #includes: in SortedCollection, yet they all implement
>one for adding new objects...

Perhaps because it's no requirement for the argument of #includes: to
respond to the sort condition, e.g.
	#(1 2 3) asSortedCollection includes: #(42)
should not be regarded as an error.
This no issue for #indexForInserting:, since its argument should obviously
be sortable.

Wim Boot




More information about the Squeak-dev mailing list