( comparator: (a: T, b: T) => number, )
| 26 | * then uses the row key as a stable tie-breaker. |
| 27 | */ |
| 28 | export function createKeyedComparator<K extends string | number, T>( |
| 29 | comparator: (a: T, b: T) => number, |
| 30 | ): (a: [K, T], b: [K, T]) => number { |
| 31 | return ([aKey, aVal], [bKey, bVal]) => { |
| 32 | // First compare on the value |
| 33 | const valueComparison = comparator(aVal, bVal) |
| 34 | if (valueComparison !== 0) { |
| 35 | return valueComparison |
| 36 | } |
| 37 | // If the values are equal, use the row key as tie-breaker |
| 38 | // This provides stable, deterministic ordering since keys are string | number |
| 39 | return compareKeys(aKey, bKey) |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | export type TopKChanges<V> = { |
| 44 | /** Indicates which element moves into the topK (if any) */ |
no test coverage detected