LOKUP opcode Vs %LOOKUP BIF
Page 1 of 1
LOKUP opcode Vs %LOOKUP BIF
The %LookUp built-in function is more than just a simple replacement for the LOOKUP operation code to allow use in /Free format logic. It offers the option of supercharging the performance of an array search operation.
Let's cover the basics first.
%LOOKUP( searchfor : array {: startindex {: numelems}})
The first parameter is the argument you're searching for, and the second parameter the name of the array where you're looking; i.e., what would have been specified in Factor 1 and 2 of the LOOKUP op code, respectively. The optional third parameter is the starting index for the search, i.e., what you could have specified as an index on the Factor 2 array.
The fourth parameter is the number of elements to search. This option didn't exist in the LOOKUP op code, so this represents the first enhancement offered by %LookUp.
Perhaps the best feature of %LookUp when compared with the op code is the ability to use a binary search rather than the much slower linear search when the data in the array is in sequence (ascending or descending).
The LookUp operation code always performs a linear search, even if the array is sequenced.
A mistake that is made more commonly than you might think is to specify Ascend or Descend on an array even when the values are not in sequence. This didn't cause a problem for the LookUp operation code when searching for an equal match, but it would cause a problem for %LookUp's binary search.
Let's cover the basics first.
%LOOKUP( searchfor : array {: startindex {: numelems}})
The first parameter is the argument you're searching for, and the second parameter the name of the array where you're looking; i.e., what would have been specified in Factor 1 and 2 of the LOOKUP op code, respectively. The optional third parameter is the starting index for the search, i.e., what you could have specified as an index on the Factor 2 array.
The fourth parameter is the number of elements to search. This option didn't exist in the LOOKUP op code, so this represents the first enhancement offered by %LookUp.
Perhaps the best feature of %LookUp when compared with the op code is the ability to use a binary search rather than the much slower linear search when the data in the array is in sequence (ascending or descending).
The LookUp operation code always performs a linear search, even if the array is sequenced.
A mistake that is made more commonly than you might think is to specify Ascend or Descend on an array even when the values are not in sequence. This didn't cause a problem for the LookUp operation code when searching for an equal match, but it would cause a problem for %LookUp's binary search.
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|