BinaryFind (open)
Does a (case sensitive) binary search within a list
Syntax
LOADLIB "wh::util/algorithms.whlib";
INTEGER FUNCTION BinaryFind(VARIANT list, VARIANT element, FUNCTION PTR comparefunction)Parameters
VARIANT listArray to search in
VARIANT elementElement to search for
FUNCTION PTR comparefunctionOptional compare function, which must return whether the first parameter should be sorted before the second (signature: BOOLEAN FUNCTION func(VARIANT a, VARIANT b)
Return value
INTEGERPosition of the first element that is greater than the searched-for element, or the end of the list if no such element can be found.
Description
This function searches for an element within a sorted list.
Examples
STRING ARRAY list := [ "b", "d", "d", "f" ];
// Returns 3
INTEGER res := BinaryFind(list, "d");
// Returns -1
INTEGER res := BinaryFind(list, "a");