Skip to Main Content
IBM Z Software


This portal is to open public enhancement requests against IBM Z Software products. To view all of your ideas submitted to IBM, create and manage groups of Ideas, or create an idea explicitly set to be either visible by all (public) or visible only to you and IBM (private), use the IBM Unified Ideas Portal (https://ideas.ibm.com).


Shape the future of IBM!

We invite you to shape the future of IBM, including product roadmaps, by submitting ideas that matter to you the most. Here's how it works:

Search existing ideas

Start by searching and reviewing ideas and requests to enhance a product or service. Take a look at ideas others have posted, and add a comment, vote, or subscribe to updates on them if they matter to you. If you can't find what you are looking for,

Post your ideas
  1. Post an idea.

  2. Get feedback from the IBM team and other customers to refine your idea.

  3. Follow the idea through the IBM Ideas process.


Specific links you will want to bookmark for future use

Welcome to the IBM Ideas Portal (https://www.ibm.com/ideas) - Use this site to find out additional information and details about the IBM Ideas process and statuses.

IBM Unified Ideas Portal (https://ideas.ibm.com) - Use this site to view all of your ideas, create new ideas for any IBM product, or search for ideas across all of IBM.

ideasibm@us.ibm.com - Use this email to suggest enhancements to the Ideas process or request help from IBM for submitting your Ideas.

Status Delivered
Workspace PL/I Compilers
Created by Guest
Created on Jan 27, 2017

Add BINSEARCH and BINSEARCHX built-in functions

We would like to have binary search built-in functions available:

position = BINSEARCH( array, key [, first, last ] )
- The 1st argument is an array - possibly nonconnected, if the items to be searched is a field in a structure
- The 2nd argument is the value to be found
- The start element as 3rd and end element 4th argument are both optional, if missing LBOUND(array) and HBOUND(array) will be used
- Either the (relative) index of the matching value will be returned or 0
- The effective index muss be calculated afterwards, if the start element is not 1

As prerequisite the array must be sorted in ascending order. For any other purpose an extended binary search has to be used:

position = BINSEARCHX( array, key, callback [, first, last ] )
- One difference is the additional callback procedure as 3rd argument
- In addition the format of the key does not need to match with the array so that e.g. an address to a key structure may be passed
- This procedure is called with the addresses to one element of the array and to the key and has to return the following:
-1 if the element is "logical smaller" than the key
0 value found
+1 if the element is "logical greater" than the key

Idea priority Low
  • Guest
    Reply
    |
    Jan 31, 2017

    this was delivered as part of APAR PI75582 / PTF UI44364

    BINSEARCH performs a binary search, using a simple compare, of an array for a specified key value and returns a size_t value that is the relative index of the key value within the array (or zero if the value is not found in the array).

    The syntax of BINSEARCH is

    BINSEARCH( x, y, [ n, [ m ] ] )

    The argument x must be a one-dimensional array, and if it is an array of NONVARYING BIT, then it must be aligned. The elements of the array must be in ascending order.
    The argument y specifies the key value to be searched for.
    The optional argument n specifies the index of the first array element to be examined. It defaults to LBOUND( x ).
    The optional argument m specifies the number of array elements - starting with the nth - to be examined. It defaults to HBOUND(x) - n + 1.

    The elements of the array x and the value must satisfy one of the following:
    Both must be computational and neither may be COMPLEX
    Both must be POINTERs
    Both must be HANDLEs to the same structure type
    Both must be ORDINALs of the same type

    If y is not found in the array, then the value zero is returned. If it is found in the array, the relative index of that value within the array is returned. The relative index is the index if the array had a lower bound of 1. So, the true index would be the returned value plus LBOUND(x)-1. For example

    If the array x has a lower bound of 0 and upper bound of 11, then the value returned will range from 0 to 12 inclusive, and if the returned value is non-zero, the true index of the found value is the returned value minus 1.

    If the array x has a lower bound of -12 and an upper bound of 12, then the returned value will range from 0 to 25 inclusive, and if the returned value is non-zero, the true index of the found value is the returned value minus 13.

    BINSEARCHX performs a binary search, using a specified compare function, of an array for a specified key value and returns a size_t value that is the relative index of the key value within the array (or zero if the value is not found in the array).

    The syntax of BINSEARCHX is

    BINSEARCHX( x, p, f, [ n, [ m ] ] )

    The argument x must be a one-dimensional array, and if it is an array of NONVARYING BIT, then it must be aligned. The elements of the array must be in ascending order.
    The argument p specifies the address of the key value to be searched for.
    The argument f specifies the function that will be invoked to perform all the required comparisons.
    The optional argument n specifies the index of the first array element to be examined. It defaults to LBOUND( x ).
    The optional argument m specifies the number of array elements - starting with the nth - to be examined. It defaults to HBOUND(x) - n + 1.

    The function f is passed 2 POINTER BYVALUE arguments: the first is the address of an array element and the second is the value of p - the address of the key value to be searched for.
    It must return BYVALUE a FIXED BIN(31) value that is -1, 0, or +1 depending on whether the value of the array element is less than, equal, or greater than, respectively, the value of the key element
    The function f must have the OPTLINK linkage

    If y is not found in the array, then the value zero is returned. If it is found in the array, the relative index of that value within the array is returned. The relative index is the index if the array had a lower bound of 1. So, the true index would be the returned value plus LBOUND(x)-1. See the description of the BINSEARCH built-in functions for some examples of how this value can vary with the bounds of the array.

  • Guest
    Reply
    |
    Jan 31, 2017

    This would be useful