UNPKG

@tanstack/db

Version:

A reactive client store for building super fast apps on sync

1 lines • 1.48 kB
{"version":3,"file":"array-utils.cjs","names":["compareKeys"],"sources":["../../../src/utils/array-utils.ts"],"sourcesContent":["import { compareKeys } from '@tanstack/db-ivm'\n\n/** Key order for descending pages, so no page needs a separate reverse pass. */\nexport function compareKeysReversed(\n a: string | number,\n b: string | number,\n): number {\n return compareKeys(b, a)\n}\n\n/**\n * Finds the correct insert position for a value in a sorted array using binary search\n * @param sortedArray The sorted array to search in\n * @param value The value to find the position for\n * @param compareFn Comparison function to use for ordering\n * @returns The index where the value should be inserted to maintain order\n */\nexport function findInsertPositionInArray<T>(\n sortedArray: Array<T>,\n value: T,\n compareFn: (a: T, b: T) => number,\n): number {\n let left = 0\n let right = sortedArray.length\n\n while (left < right) {\n const mid = Math.floor((left + right) / 2)\n const comparison = compareFn(sortedArray[mid]!, value)\n\n if (comparison < 0) {\n left = mid + 1\n } else {\n right = mid\n }\n }\n\n return left\n}\n"],"mappings":";AAGA,SAAgB,oBACd,GACA,GACQ;CACR,QAAA,GAAOA,iBAAAA,YAAAA,CAAY,GAAG,CAAC;AACzB;AASA,SAAgB,0BACd,aACA,OACA,WACQ;CACR,IAAI,OAAO;CACX,IAAI,QAAQ,YAAY;CAExB,OAAO,OAAO,OAAO;EACnB,MAAM,MAAM,KAAK,OAAO,OAAO,SAAS,CAAC;EAGzC,IAFmB,UAAU,YAAY,MAAO,KAE5C,IAAa,GACf,OAAO,MAAM;OAEb,QAAQ;CAEZ;CAEA,OAAO;AACT"}