export interface PositionCacheConfig { totalItemsFn: () => number; sizeFn: (index: number) => number; defaultSizeFn: () => number; } /** * Cumulative prefix sum cache for O(log n) scroll-to-index lookups. * * Works for both row heights and column widths. Builds an array where * prefixSum[i] = sum of sizes for items 0..i-1. * prefixSum[0] = 0, prefixSum[n] = total size of all n items. * * Binary search on this array converts a pixel offset to an index in O(log n) * instead of O(n) linear iteration. * * @class PositionCache */ export declare class PositionCache { #private; /** * The prefix sum array. Contains the cumulative size of all items up to the index. * * @type {Float64Array|null} */ prefixSum: Float64Array | null; /** * The total number of items (rows or columns). * * @type {number} */ totalItems: number; /** * @param {object} config The configuration object. * @param {Function} config.totalItemsFn A function that returns the total number of items (rows or columns). * @param {Function} config.sizeFn A function that returns the size for a given index. * @param {Function} config.defaultSizeFn A function that returns the default size for items * that return NaN/undefined. */ constructor({ totalItemsFn, sizeFn, defaultSizeFn }: PositionCacheConfig); /** * Builds the prefix sum by reading the current total items, size function, * and default size from the configured providers. */ build(): void; /** * Returns the cumulative size at an index (sum of items 0..index-1). * * @param {number} index The item index. * @returns {number} The cumulative size before this index. */ getOffset(index: number): number; /** * Finds the item index at a given pixel offset using binary search. * * @param {number} offset The pixel offset. * @returns {number} The index whose cumulative start position is at or just before the offset. * Returns `0` when there are no items (`totalItems === 0`), including when `offset > 0`. */ findIndexAtOffset(offset: number): number; /** * Returns the size of a single item at the given index. * * @param {number} index The item index. * @returns {number} The size of the item (difference between consecutive prefix sums). */ getSizeAt(index: number): number; /** * Builds the prefix sum only when the cache is not yet built or the item * count has changed. */ ensureBuilt(): void; /** * Returns the total size of all items. * * @returns {number} */ getTotalSize(): number; /** * Invalidates the cache so it will be rebuilt on the next * {@link PositionCache#ensureBuilt} call. */ invalidate(): void; /** * Returns whether the cache has been built. * * @returns {boolean} */ isBuilt(): this is PositionCache & { prefixSum: Float64Array; }; }