[ENH] Interval method indexOf:

Boris Gaertner Boris.Gaertner at gmx.net
Tue Jun 15 21:27:29 UTC 2004


"Boris Gaertner" <Boris.Gaertner at gmx.net> wrote:


>
> Interval inherits #indexOf:startingAt:ifAbsent: from
SequenceableCollection.
> The inherited method enumerates all elements until it finds a hit. Try
>
>  (1 to: 100000 by: 0.01) indexOf: 99999
>
> to see that this can be extremely time consuming. For Intervals, we can do
> better.
>

The code that I posted earlier today is wrong:
For
   (1 to: 10 by: 0.1) indexOf: 1000
the correct answer is 0, but my code answers 9991,
This is a stupid mistake, because the check that is
needed here, is available - I simply did not use
what is available. The method
  indexOf:startingAt:ifAbsent:
has to check:

    (self rangeIncludes: anElement)
      ifFalse: [^0].

The attached change set contaisn a method that performs
that check.

In a separate mail, I will post two additional tests.

My apologies for my mistake and greetings;
Boris



-------------- next part --------------
A non-text attachment was scrubbed...
Name: IntervalIndexEnh.3.cs
Type: application/octet-stream
Size: 1347 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20040615/954e7236/IntervalIndexEnh.3.obj


More information about the Squeak-dev mailing list