Appearance
KBE3D / KBCore / Cesium / binarySearch
函数: binarySearch()
binarySearch(
array:any[] |Float32Array<ArrayBufferLike> |Int8Array<ArrayBufferLike> |Uint8Array<ArrayBufferLike> |Int16Array<ArrayBufferLike> |Uint16Array<ArrayBufferLike> |Int32Array<ArrayBufferLike> |Uint32Array<ArrayBufferLike> |Float64Array<ArrayBufferLike>,itemToFind:any,comparator:binarySearchComparator):number
Finds an item in a sorted array.
参数
array
The sorted array to search.
any[] | Float32Array<ArrayBufferLike> | Int8Array<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | Int16Array<ArrayBufferLike> | Uint16Array<ArrayBufferLike> | Int32Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike> | Float64Array<ArrayBufferLike>
itemToFind
any
The item to find in the array.
comparator
The function to use to compare the item to elements in the array.
返回
number
The index of itemToFind in the array, if it exists. If itemToFind does not exist, the return value is a negative number which is the bitwise complement (~) of the index before which the itemToFind should be inserted in order to maintain the sorted order of the array.
示例
ts
// Create a comparator function to search through an array of numbers.
function comparator(a, b) {
return a - b;
};
const numbers = [0, 2, 4, 6, 8];
const index = Cesium.binarySearch(numbers, 6, comparator); // 3