@electric-sql/d2ts
Version:
D2TS is a TypeScript implementation of Differential Dataflow.
40 lines (39 loc) • 2.06 kB
TypeScript
import { KeyValue, PipedOperator } from '../../types.js';
import { DifferenceStreamReader, DifferenceStreamWriter, UnaryOperator } from '../../graph.js';
import { Antichain } from '../../order.js';
import { SQLiteDb } from '../database.js';
interface TopKWithFractionalIndexOptions {
limit?: number;
offset?: number;
db?: SQLiteDb;
}
/**
* Operator for fractional indexed topK operations
* This operator maintains fractional indices for sorted elements
* and only updates indices when elements move position
*/
export declare class TopKWithFractionalIndexOperator<K, V1> extends UnaryOperator<[
K,
V1 | [V1, string]
]> {
#private;
constructor(id: number, inputA: DifferenceStreamReader<[K, V1]>, output: DifferenceStreamWriter<[K, [V1, string]]>, comparator: (a: V1, b: V1) => number, options: TopKWithFractionalIndexOptions, initialFrontier: Antichain, db: SQLiteDb);
run(): void;
destroy(): void;
}
/**
* Limits the number of results based on a comparator, with optional offset.
* This works on a keyed stream, where the key is the first element of the tuple
* The ordering is withing a key group, i.e. elements are sorted within a key group
* and the limit + offset is applied to that sorted group.
* To order the entire stream, key by the same value for all elements such as null.
* Adds a fractional index of the element to the result as [key, [value, index]]
* This is useful for stable ordering in UIs.
*
* @param comparator - A function that compares two elements
* @param db - Optional SQLite database (can be injected via context)
* @param options - An optional object containing limit and offset properties
* @returns A piped operator that orders the elements and limits the number of results
*/
export declare function topKWithFractionalIndex<K extends T extends KeyValue<infer K, infer _V> ? K : never, V1 extends T extends KeyValue<K, infer V> ? V : never, T>(comparator: (a: V1, b: V1) => number, options?: TopKWithFractionalIndexOptions): PipedOperator<T, KeyValue<K, [V1, string]>>;
export {};