× 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.

 Subject: Re: Keyed Array Data Structures From: Vinay Gavankar Date: Fri, 2 Dec 2022 10:38:25 -0500 List-archive: List-post: List-subscribe: , List-unsubscribe: ,

Hi Mark,

*Since a binary search is used by the %LOOKUPxx built-in functions for a
sequenced array*

I think the key words here are "sequenced array". For that it must be
'defined' with Ascend or Descend. I don't know how to add that keyword on
data structure array (I get compile error).

Am I missing something?

On Fri, Dec 2, 2022 at 10:20 AM Mark Waterbury <
mark.s.waterbury@xxxxxxxxxxxxx> wrote:

Vinay,
A binary search is exactly what %lookup does. For that algorithm to work
correctly, you must ensure that the table or array is sorted properly.
See: https://www.rpgpgm.com/2015/09/when-lookup-ne-lookup.html

Excerpt from the above article below:
Referring to IBM's KnowledgeCenter I found a link at the bottom of
the %LOKUPxx page that took me to a page called: Sequenced arrays that are
not in the correct sequence ... an interesting passage on this page states:

... the %LOOKUPxx built-in functions and the LOOKUP operation code may
find different values. The %LOOKUPxx built-in functions may not find a data
value even if it is present in the array.

Since a binary search is used by the %LOOKUPxx built-in functions for a
sequenced array, and the correct function of a binary search depends on the
data being in order, the search may only look at a few elements of the
array. When the array is out of order, the result of a binary search is
unpredictable.

See:
- %LOOKUPxx BIF
- LOOKUP Operation code
- Sequenced arrays that are not in the correct sequence

Hope that helps,
Mark S. Waterbury

On Friday, December 2, 2022 at 09:25:54 AM EST, Vinay Gavankar <
vinaygav@xxxxxxxxx> wrote:

Hi,

Is there a way to define a "sequenced" keyed array data structure, so that
the system uses Binary Search when doing a %lookupxx on it using the key?

TIA
Vinay
--
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

questions.

Help support midrange.com by shopping at amazon.com with our affiliate

--
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

questions.

Help support midrange.com by shopping at amazon.com with our affiliate

As an Amazon Associate we earn from qualifying purchases.

Follow-Ups:

Replies:

This mailing list archive is Copyright 1997-2023 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.