RecordRange (open)
Does a (case sensitive) binary search within a sorted record array, returns all matching records
Syntax
LOADLIB "wh::util/algorithms.whlib";
RECORD ARRAY FUNCTION RecordRange(RECORD ARRAY list, RECORD element, STRING ARRAY cellnames)Parameters
RECORD ARRAY listRecord array to search in
RECORD elementRecord with values to search for
STRING ARRAY cellnamesNames 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
RECORD ARRAYThe range of records that match the values.
Description
This function searches for records with specific values within a record array that is sorted on specific cells. The range of matching records are returned.
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 [ [ a := 3, b := 1, text := "second value" ]
// , [ a := 3, b := 1, text := "second value again" ]
// , [ a := 3, b := 3, text := "value 3" ]
// ]
RECORD ARRAY res := RecordRange(list, [ a := 3 ], [ "A" ]);
// Returns DEFAULT RECORD ARRAY
INTEGER res := RecordRange(list, [ a := 5, b := 8 ], [ "A", "B" ]);