× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On Tue, Aug 9, 2011 at 7:05 PM, Joe Pluta <joepluta@xxxxxxxxxxxxxxxxx> wrote:
Anyway, the %LOOKUP BIF uses a binary scan where
LOOKUP does not.  Jon and Susan wrote about that
when V5R1 came out.

Alas I was not aware of Jon and Susan until fairly recently. Indeed,
their articles are a nice resource. But I am still kind of surprised
that LOOKUP never used binary search.

Anyway, I searched for that article just now:

<http://www.ibmsystemsmag.com/ibmi/developer/rpg/iSeries-EXTRA--Look-Before-You--Lookup/>

And I think that article, combined with Mark's response, may explain
what I'm seeing:

On Tue, Aug 9, 2011 at 7:34 PM, M. Lazarus <mlazarus@xxxxxxxx> wrote:
You should be able to solve your problem by removing the "ascend"
keyword from the conv definition.

I will have to check at work tomorrow, but I think what you are trying
to tell me is that I have a 1500-element array, with only 794
populated elements, and since I haven't done anything special to
ensure that those elements at the end are higher than the 794
populated ones, my array is actually NOT sorted! Meaning *I* have
ruined the binary search.

It all makes sense now. 750 of the elements are in the "low" half of
the array, and as long as what I'm searching for is in that half,
binary search will find it. But when I looked for an element in the
"high" half, it saw that what I was looking for was higher than the
middle element, and thus it next looked at the "three quarters"
element, which was blank, and whether %LOOKUP gives up right away at
that point (because it should realize at that point that the array is
not sorted), or continues trying to apply binary search logic, it
never gets back down into that space between halfway and three
quarters, where my element can actually be found.

So thank you Joe and Mark. I expect that once I "high-value-fill" my
array, I will be able to find all my elements and still keep the
binary search performance.

And so I have to admit, Joe, you were right to mock me for doubting
the language before doubting myself. (I still think the language has
its warts, but in this case, it held up its end of the bargain and I
didn't.)

John Y.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.