* Internal method for taking items from the index. * @param n - The number of items to return * @param nextPair - Function to get the next pair from the BTree * @param from - Already normalized! undefined means "start from beginning/end", sentinel means "start from the key undefined" * @
(
n: number,
nextPair: (k?: any) => [any, any] | undefined,
from: any,
filterFn?: (key: TKey) => boolean,
reversed: boolean = false,
)
| 299 | * @param reversed - Whether to reverse the order of keys within each value |
| 300 | */ |
| 301 | private takeInternal( |
| 302 | n: number, |
| 303 | nextPair: (k?: any) => [any, any] | undefined, |
| 304 | from: any, |
| 305 | filterFn?: (key: TKey) => boolean, |
| 306 | reversed: boolean = false, |
| 307 | ): Array<TKey> { |
| 308 | const keysInResult: Set<TKey> = new Set() |
| 309 | const result: Array<TKey> = [] |
| 310 | let pair: [any, any] | undefined |
| 311 | let key = from // Use as-is - it's already normalized by the caller |
| 312 | |
| 313 | while ((pair = nextPair(key)) !== undefined && result.length < n) { |
| 314 | key = pair[0] |
| 315 | const keys = this.valueMap.get(key) as |
| 316 | | Set<Exclude<TKey, undefined>> |
| 317 | | undefined |
| 318 | if (keys && keys.size > 0) { |
| 319 | // Sort keys for deterministic order, reverse if needed |
| 320 | const sorted = Array.from(keys).sort(compareKeys) |
| 321 | if (reversed) sorted.reverse() |
| 322 | for (const ks of sorted) { |
| 323 | if (result.length >= n) break |
| 324 | if (!keysInResult.has(ks) && (filterFn?.(ks) ?? true)) { |
| 325 | result.push(ks) |
| 326 | keysInResult.add(ks) |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | return result |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * Returns the next n items after the provided item. |
no test coverage detected