import cmp from"./cmp.js";function binarySearch(records,key){let mid,low=0,high=records.length;for(;low<high;)mid=low+high>>>1,cmp(records[mid].key,key)<0?low=mid+1:high=mid;return low}export function getIndexByKey(records,key){const idx=binarySearch(records,key),record=records[idx];return record&&0===cmp(record.key,key)?idx:-1}export function getByKey(records,key){return records[getIndexByKey(records,key)]}export function getIndexByKeyRange(records,keyRange){const lowerIdx=void 0===keyRange.lower?0:binarySearch(records,keyRange.lower),upperIdx=void 0===keyRange.upper?records.length-1:binarySearch(records,keyRange.upper);for(let i=lowerIdx;i<=upperIdx;i++){const record=records[i];if(record&&keyRange.includes(record.key))return i}return-1}export function getByKeyRange(records,keyRange){return records[getIndexByKeyRange(records,keyRange)]}export function getIndexByKeyGTE(records,key){const idx=binarySearch(records,key),record=records[idx];return record&&cmp(record.key,key)>=0?idx:-1}