RecordBinaryFind (open)

Does a (case sensitive) binary search within a sorted record array

Syntax

LOADLIB "wh::util/algorithms.whlib";

INTEGER FUNCTION RecordBinaryFind(RECORD ARRAY list, RECORD element, STRING ARRAY cellnames)

Parameters

RECORD ARRAY list

Record array to search in

RECORD element

Record with values to search for

STRING ARRAY cellnames

Names of cells to search for (the list must be ordered on these cellnames, in the same order they are passed to this function)

Return value

INTEGER

Position of the the matching element, or -1 if not found

Description

This function searches for an record with specific values within a record array that is sorted on specific cells.

Examples


// List (sorted on 'a', then 'b')
RECORD ARRAY list :=
    [ [ a := 1, b := 10, text := "value 1" ]
    , [ a := 3, b := 1,  text := "second value" ]
    , [ a := 3, b := 1,  text := "second value again" ]
    , [ a := 3, b := 3,  text := "value 3" ]
    , [ a := 5, b := 7,  text := "last value" ]
    ];

// Returns 3
INTEGER res := RecordBinaryFind(list, [ a := 3, b := 1 ], [ "A", "B" ]);

// Returns -1
INTEGER res := RecordBinaryFind(list, [ a := 1, b := 8 ], [ "A", "B" ]);