BinarySearch
The BinarySearch module provides an implementation of the binary search algorithm for quickly
finding an element within a sorted sequence. The BinarySearch.Table API is provided for easily
searching through a table, as well as a BinarySearch.Raw API for searching an arbitrary data
sequence via a specified function.
API
-
class Util.BinarySearch:
LibTSMModule -
staticmethod Raw(
numEntries:number,
searchValue: <V:string|number>,
valueFunc: fun(index:number, ...any): <V:string|number>,
...:any
): (index?:number, insertIndex:number) Performs a raw binary search.
- Parameters:
numEntries (
number) – The total number of entriessearchValue (<V:
string|number>) – The value to search forvalueFunc (fun(index:
number, ...any): <V:string|number>) – A function to call to get a comparable value for the specified index... (
any) – Extra values to pass to valueFunc
-
staticmethod Table(
tbl: <T:any>[] | <V:string|number>[],
searchValue: <V:string|number>,
valueFunc?: fun(value: <T:any>): <V:string|number>
): (index:number|nil, insertIndex:number) Performs a binary search on a table.
- Parameters:
tbl (<T:
any>[] | <V:string|number>[]) – The table to searchsearchValue (<V:
string|number>) – The value to search forvalueFunc? (fun(value: <T:
any>): <V:string|number>) – An optional function to get the value from a table entry
-
staticmethod Raw(