[Q]uestions regarding collections
Aaron
reic0024 at d.umn.edu
Sun Aug 19 01:49:07 UTC 2001
On Saturday, August 18, 2001, at 08:30 PM, Bob Arning wrote:
> On Sat, 18 Aug 2001 18:11:16 -0600 Jon Hylands <jon at huv.com> wrote:
>> On Sat, 18 Aug 2001 21:59:35 +0200, "Raymond Tiefenthal"
>> <r.tiefenthal at gmx.de> wrote:
>>
>>> 3. I was asking myself, why SortedCollection doesn't overwrite #
>>> indexOf:
>>> for instance, in order to perform a binary search.
>>
>> In order to do a binary search, you have to know whether the
>> collection is
>> sorted ascending or descending.
>>
>> Without knowing what the sort block does, I can't see how the
>> collection
>> could figure out which way to go after the first comparison...
>
> It's not that hard, I think. A few probes, say at 1 and N, should tell
> you which way the collection was ordered. From then it would be an
> ordinary binary search.
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.
Regards,
Aaron
More information about the Squeak-dev
mailing list
|