@tanstack/db-ivm 0.0.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/cjs/d2.cjs +111 -0
- package/dist/cjs/d2.cjs.map +1 -0
- package/dist/cjs/d2.d.cts +45 -0
- package/dist/cjs/graph.cjs +90 -0
- package/dist/cjs/graph.cjs.map +1 -0
- package/dist/cjs/graph.d.cts +57 -0
- package/dist/cjs/index.cjs +72 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +4 -0
- package/dist/cjs/indexes.cjs +104 -0
- package/dist/cjs/indexes.cjs.map +1 -0
- package/dist/cjs/indexes.d.cts +20 -0
- package/dist/cjs/multiset.cjs +173 -0
- package/dist/cjs/multiset.cjs.map +1 -0
- package/dist/cjs/multiset.d.cts +36 -0
- package/dist/cjs/operators/concat.cjs +37 -0
- package/dist/cjs/operators/concat.cjs.map +1 -0
- package/dist/cjs/operators/concat.d.cts +13 -0
- package/dist/cjs/operators/consolidate.cjs +40 -0
- package/dist/cjs/operators/consolidate.cjs.map +1 -0
- package/dist/cjs/operators/consolidate.d.cts +12 -0
- package/dist/cjs/operators/count.cjs +36 -0
- package/dist/cjs/operators/count.cjs.map +1 -0
- package/dist/cjs/operators/count.d.cts +13 -0
- package/dist/cjs/operators/debug.cjs +50 -0
- package/dist/cjs/operators/debug.cjs.map +1 -0
- package/dist/cjs/operators/debug.d.cts +16 -0
- package/dist/cjs/operators/distinct.cjs +78 -0
- package/dist/cjs/operators/distinct.cjs.map +1 -0
- package/dist/cjs/operators/distinct.d.cts +14 -0
- package/dist/cjs/operators/filter.cjs +43 -0
- package/dist/cjs/operators/filter.cjs.map +1 -0
- package/dist/cjs/operators/filter.d.cts +16 -0
- package/dist/cjs/operators/filterBy.cjs +19 -0
- package/dist/cjs/operators/filterBy.cjs.map +1 -0
- package/dist/cjs/operators/filterBy.d.cts +10 -0
- package/dist/cjs/operators/groupBy.cjs +225 -0
- package/dist/cjs/operators/groupBy.cjs.map +1 -0
- package/dist/cjs/operators/groupBy.d.cts +68 -0
- package/dist/cjs/operators/index.d.cts +18 -0
- package/dist/cjs/operators/join.cjs +145 -0
- package/dist/cjs/operators/join.cjs.map +1 -0
- package/dist/cjs/operators/join.d.cts +48 -0
- package/dist/cjs/operators/keying.cjs +16 -0
- package/dist/cjs/operators/keying.cjs.map +1 -0
- package/dist/cjs/operators/keying.d.cts +19 -0
- package/dist/cjs/operators/map.cjs +43 -0
- package/dist/cjs/operators/map.cjs.map +1 -0
- package/dist/cjs/operators/map.d.cts +16 -0
- package/dist/cjs/operators/negate.cjs +28 -0
- package/dist/cjs/operators/negate.cjs.map +1 -0
- package/dist/cjs/operators/negate.d.cts +13 -0
- package/dist/cjs/operators/orderBy.cjs +102 -0
- package/dist/cjs/operators/orderBy.cjs.map +1 -0
- package/dist/cjs/operators/orderBy.d.cts +38 -0
- package/dist/cjs/operators/orderByBTree.d.cts +3 -0
- package/dist/cjs/operators/output.cjs +46 -0
- package/dist/cjs/operators/output.cjs.map +1 -0
- package/dist/cjs/operators/output.d.cts +16 -0
- package/dist/cjs/operators/pipe.cjs +9 -0
- package/dist/cjs/operators/pipe.cjs.map +1 -0
- package/dist/cjs/operators/pipe.d.cts +21 -0
- package/dist/cjs/operators/reduce.cjs +99 -0
- package/dist/cjs/operators/reduce.cjs.map +1 -0
- package/dist/cjs/operators/reduce.d.cts +14 -0
- package/dist/cjs/operators/topK.cjs +39 -0
- package/dist/cjs/operators/topK.cjs.map +1 -0
- package/dist/cjs/operators/topK.d.cts +32 -0
- package/dist/cjs/operators/topKWithFractionalIndex.cjs +218 -0
- package/dist/cjs/operators/topKWithFractionalIndex.cjs.map +1 -0
- package/dist/cjs/operators/topKWithFractionalIndex.d.cts +58 -0
- package/dist/cjs/operators/topKWithFractionalIndexBTree.d.cts +27 -0
- package/dist/cjs/types.d.cts +30 -0
- package/dist/cjs/utils.cjs +125 -0
- package/dist/cjs/utils.cjs.map +1 -0
- package/dist/cjs/utils.d.cts +40 -0
- package/dist/esm/d2.d.ts +45 -0
- package/dist/esm/d2.js +111 -0
- package/dist/esm/d2.js.map +1 -0
- package/dist/esm/graph.d.ts +57 -0
- package/dist/esm/graph.js +90 -0
- package/dist/esm/graph.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +72 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/indexes.d.ts +20 -0
- package/dist/esm/indexes.js +104 -0
- package/dist/esm/indexes.js.map +1 -0
- package/dist/esm/multiset.d.ts +36 -0
- package/dist/esm/multiset.js +173 -0
- package/dist/esm/multiset.js.map +1 -0
- package/dist/esm/operators/concat.d.ts +13 -0
- package/dist/esm/operators/concat.js +37 -0
- package/dist/esm/operators/concat.js.map +1 -0
- package/dist/esm/operators/consolidate.d.ts +12 -0
- package/dist/esm/operators/consolidate.js +40 -0
- package/dist/esm/operators/consolidate.js.map +1 -0
- package/dist/esm/operators/count.d.ts +13 -0
- package/dist/esm/operators/count.js +36 -0
- package/dist/esm/operators/count.js.map +1 -0
- package/dist/esm/operators/debug.d.ts +16 -0
- package/dist/esm/operators/debug.js +50 -0
- package/dist/esm/operators/debug.js.map +1 -0
- package/dist/esm/operators/distinct.d.ts +14 -0
- package/dist/esm/operators/distinct.js +78 -0
- package/dist/esm/operators/distinct.js.map +1 -0
- package/dist/esm/operators/filter.d.ts +16 -0
- package/dist/esm/operators/filter.js +43 -0
- package/dist/esm/operators/filter.js.map +1 -0
- package/dist/esm/operators/filterBy.d.ts +10 -0
- package/dist/esm/operators/filterBy.js +19 -0
- package/dist/esm/operators/filterBy.js.map +1 -0
- package/dist/esm/operators/groupBy.d.ts +68 -0
- package/dist/esm/operators/groupBy.js +225 -0
- package/dist/esm/operators/groupBy.js.map +1 -0
- package/dist/esm/operators/index.d.ts +18 -0
- package/dist/esm/operators/join.d.ts +48 -0
- package/dist/esm/operators/join.js +145 -0
- package/dist/esm/operators/join.js.map +1 -0
- package/dist/esm/operators/keying.d.ts +19 -0
- package/dist/esm/operators/keying.js +16 -0
- package/dist/esm/operators/keying.js.map +1 -0
- package/dist/esm/operators/map.d.ts +16 -0
- package/dist/esm/operators/map.js +43 -0
- package/dist/esm/operators/map.js.map +1 -0
- package/dist/esm/operators/negate.d.ts +13 -0
- package/dist/esm/operators/negate.js +28 -0
- package/dist/esm/operators/negate.js.map +1 -0
- package/dist/esm/operators/orderBy.d.ts +38 -0
- package/dist/esm/operators/orderBy.js +102 -0
- package/dist/esm/operators/orderBy.js.map +1 -0
- package/dist/esm/operators/orderByBTree.d.ts +3 -0
- package/dist/esm/operators/output.d.ts +16 -0
- package/dist/esm/operators/output.js +46 -0
- package/dist/esm/operators/output.js.map +1 -0
- package/dist/esm/operators/pipe.d.ts +21 -0
- package/dist/esm/operators/pipe.js +9 -0
- package/dist/esm/operators/pipe.js.map +1 -0
- package/dist/esm/operators/reduce.d.ts +14 -0
- package/dist/esm/operators/reduce.js +99 -0
- package/dist/esm/operators/reduce.js.map +1 -0
- package/dist/esm/operators/topK.d.ts +32 -0
- package/dist/esm/operators/topK.js +39 -0
- package/dist/esm/operators/topK.js.map +1 -0
- package/dist/esm/operators/topKWithFractionalIndex.d.ts +58 -0
- package/dist/esm/operators/topKWithFractionalIndex.js +218 -0
- package/dist/esm/operators/topKWithFractionalIndex.js.map +1 -0
- package/dist/esm/operators/topKWithFractionalIndexBTree.d.ts +27 -0
- package/dist/esm/types.d.ts +30 -0
- package/dist/esm/utils.d.ts +40 -0
- package/dist/esm/utils.js +125 -0
- package/dist/esm/utils.js.map +1 -0
- package/package.json +6 -7
- package/src/operators/orderBy.ts +11 -29
- package/src/operators/topKWithFractionalIndex.ts +69 -57
- package/src/operators/topKWithFractionalIndexBTree.ts +14 -19
package/dist/esm/d2.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { DifferenceStreamWriter, BinaryOperator, DifferenceStreamReader, UnaryOperator } from './graph.js';
|
|
2
|
+
import { MultiSet, MultiSetArray } from './multiset.js';
|
|
3
|
+
import { ID2, IStreamBuilder, PipedOperator } from './types.js';
|
|
4
|
+
export declare class D2 implements ID2 {
|
|
5
|
+
#private;
|
|
6
|
+
constructor();
|
|
7
|
+
getNextOperatorId(): number;
|
|
8
|
+
newInput<T>(): RootStreamBuilder<T>;
|
|
9
|
+
addOperator(operator: UnaryOperator<any> | BinaryOperator<any>): void;
|
|
10
|
+
addStream(stream: DifferenceStreamReader<any>): void;
|
|
11
|
+
finalize(): void;
|
|
12
|
+
step(): void;
|
|
13
|
+
pendingWork(): boolean;
|
|
14
|
+
run(): void;
|
|
15
|
+
}
|
|
16
|
+
export declare class StreamBuilder<T> implements IStreamBuilder<T> {
|
|
17
|
+
#private;
|
|
18
|
+
constructor(graph: ID2, writer: DifferenceStreamWriter<T>);
|
|
19
|
+
connectReader(): DifferenceStreamReader<T>;
|
|
20
|
+
get writer(): DifferenceStreamWriter<T>;
|
|
21
|
+
get graph(): ID2;
|
|
22
|
+
pipe<O>(o1: PipedOperator<T, O>): IStreamBuilder<O>;
|
|
23
|
+
pipe<T2, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, O>): IStreamBuilder<O>;
|
|
24
|
+
pipe<T2, T3, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, O>): IStreamBuilder<O>;
|
|
25
|
+
pipe<T2, T3, T4, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, O>): IStreamBuilder<O>;
|
|
26
|
+
pipe<T2, T3, T4, T5, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, O>): IStreamBuilder<O>;
|
|
27
|
+
pipe<T2, T3, T4, T5, T6, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, O>): IStreamBuilder<O>;
|
|
28
|
+
pipe<T2, T3, T4, T5, T6, T7, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, O>): IStreamBuilder<O>;
|
|
29
|
+
pipe<T2, T3, T4, T5, T6, T7, T8, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, O>): IStreamBuilder<O>;
|
|
30
|
+
pipe<T2, T3, T4, T5, T6, T7, T8, T9, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, O>): IStreamBuilder<O>;
|
|
31
|
+
pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, O>): IStreamBuilder<O>;
|
|
32
|
+
pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, O>): IStreamBuilder<O>;
|
|
33
|
+
pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, O>): IStreamBuilder<O>;
|
|
34
|
+
pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, O>): IStreamBuilder<O>;
|
|
35
|
+
pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, O>): IStreamBuilder<O>;
|
|
36
|
+
pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, O>): IStreamBuilder<O>;
|
|
37
|
+
pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, T16>, o16: PipedOperator<T16, O>): IStreamBuilder<O>;
|
|
38
|
+
pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, T16>, o16: PipedOperator<T16, T17>, o17: PipedOperator<T17, O>): IStreamBuilder<O>;
|
|
39
|
+
pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, T16>, o16: PipedOperator<T16, T17>, o17: PipedOperator<T17, T18>, o18: PipedOperator<T18, O>): IStreamBuilder<O>;
|
|
40
|
+
pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, T16>, o16: PipedOperator<T16, T17>, o17: PipedOperator<T17, T18>, o18: PipedOperator<T18, T19>, o19: PipedOperator<T19, O>): IStreamBuilder<O>;
|
|
41
|
+
pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, T16>, o16: PipedOperator<T16, T17>, o17: PipedOperator<T17, T18>, o18: PipedOperator<T18, T19>, o19: PipedOperator<T19, T20>, o20: PipedOperator<T20, O>): IStreamBuilder<O>;
|
|
42
|
+
}
|
|
43
|
+
export declare class RootStreamBuilder<T> extends StreamBuilder<T> {
|
|
44
|
+
sendData(collection: MultiSet<T> | MultiSetArray<T>): void;
|
|
45
|
+
}
|
package/dist/esm/d2.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
9
|
+
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
10
|
+
set _(value) {
|
|
11
|
+
__privateSet(obj, member, value, setter);
|
|
12
|
+
},
|
|
13
|
+
get _() {
|
|
14
|
+
return __privateGet(obj, member, getter);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
var _streams, _operators, _nextOperatorId, _finalized, _D2_instances, checkNotFinalized_fn, _graph, _writer;
|
|
18
|
+
import { DifferenceStreamWriter } from "./graph.js";
|
|
19
|
+
class D2 {
|
|
20
|
+
constructor() {
|
|
21
|
+
__privateAdd(this, _D2_instances);
|
|
22
|
+
__privateAdd(this, _streams, []);
|
|
23
|
+
__privateAdd(this, _operators, []);
|
|
24
|
+
__privateAdd(this, _nextOperatorId, 0);
|
|
25
|
+
__privateAdd(this, _finalized, false);
|
|
26
|
+
}
|
|
27
|
+
getNextOperatorId() {
|
|
28
|
+
__privateMethod(this, _D2_instances, checkNotFinalized_fn).call(this);
|
|
29
|
+
return __privateWrapper(this, _nextOperatorId)._++;
|
|
30
|
+
}
|
|
31
|
+
newInput() {
|
|
32
|
+
__privateMethod(this, _D2_instances, checkNotFinalized_fn).call(this);
|
|
33
|
+
const writer = new DifferenceStreamWriter();
|
|
34
|
+
const streamBuilder = new RootStreamBuilder(this, writer);
|
|
35
|
+
__privateGet(this, _streams).push(streamBuilder.connectReader());
|
|
36
|
+
return streamBuilder;
|
|
37
|
+
}
|
|
38
|
+
addOperator(operator) {
|
|
39
|
+
__privateMethod(this, _D2_instances, checkNotFinalized_fn).call(this);
|
|
40
|
+
__privateGet(this, _operators).push(operator);
|
|
41
|
+
}
|
|
42
|
+
addStream(stream) {
|
|
43
|
+
__privateMethod(this, _D2_instances, checkNotFinalized_fn).call(this);
|
|
44
|
+
__privateGet(this, _streams).push(stream);
|
|
45
|
+
}
|
|
46
|
+
finalize() {
|
|
47
|
+
__privateMethod(this, _D2_instances, checkNotFinalized_fn).call(this);
|
|
48
|
+
__privateSet(this, _finalized, true);
|
|
49
|
+
}
|
|
50
|
+
step() {
|
|
51
|
+
if (!__privateGet(this, _finalized)) {
|
|
52
|
+
throw new Error(`Graph not finalized`);
|
|
53
|
+
}
|
|
54
|
+
for (const op of __privateGet(this, _operators)) {
|
|
55
|
+
op.run();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
pendingWork() {
|
|
59
|
+
return __privateGet(this, _operators).some((op) => op.hasPendingWork());
|
|
60
|
+
}
|
|
61
|
+
run() {
|
|
62
|
+
while (this.pendingWork()) {
|
|
63
|
+
this.step();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
_streams = new WeakMap();
|
|
68
|
+
_operators = new WeakMap();
|
|
69
|
+
_nextOperatorId = new WeakMap();
|
|
70
|
+
_finalized = new WeakMap();
|
|
71
|
+
_D2_instances = new WeakSet();
|
|
72
|
+
checkNotFinalized_fn = function() {
|
|
73
|
+
if (__privateGet(this, _finalized)) {
|
|
74
|
+
throw new Error(`Graph already finalized`);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
class StreamBuilder {
|
|
78
|
+
constructor(graph, writer) {
|
|
79
|
+
__privateAdd(this, _graph);
|
|
80
|
+
__privateAdd(this, _writer);
|
|
81
|
+
__privateSet(this, _graph, graph);
|
|
82
|
+
__privateSet(this, _writer, writer);
|
|
83
|
+
}
|
|
84
|
+
connectReader() {
|
|
85
|
+
return __privateGet(this, _writer).newReader();
|
|
86
|
+
}
|
|
87
|
+
get writer() {
|
|
88
|
+
return __privateGet(this, _writer);
|
|
89
|
+
}
|
|
90
|
+
get graph() {
|
|
91
|
+
return __privateGet(this, _graph);
|
|
92
|
+
}
|
|
93
|
+
pipe(...operators) {
|
|
94
|
+
return operators.reduce((stream, operator) => {
|
|
95
|
+
return operator(stream);
|
|
96
|
+
}, this);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
_graph = new WeakMap();
|
|
100
|
+
_writer = new WeakMap();
|
|
101
|
+
class RootStreamBuilder extends StreamBuilder {
|
|
102
|
+
sendData(collection) {
|
|
103
|
+
this.writer.sendData(collection);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export {
|
|
107
|
+
D2,
|
|
108
|
+
RootStreamBuilder,
|
|
109
|
+
StreamBuilder
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=d2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"d2.js","sources":["../../src/d2.ts"],"sourcesContent":["import { DifferenceStreamWriter } from \"./graph.js\"\nimport type {\n BinaryOperator,\n DifferenceStreamReader,\n UnaryOperator,\n} from \"./graph.js\"\nimport type { MultiSet, MultiSetArray } from \"./multiset.js\"\nimport type { ID2, IStreamBuilder, PipedOperator } from \"./types.js\"\n\nexport class D2 implements ID2 {\n #streams: Array<DifferenceStreamReader<any>> = []\n #operators: Array<UnaryOperator<any> | BinaryOperator<any>> = []\n #nextOperatorId = 0\n #finalized = false\n\n constructor() {}\n\n #checkNotFinalized(): void {\n if (this.#finalized) {\n throw new Error(`Graph already finalized`)\n }\n }\n\n getNextOperatorId(): number {\n this.#checkNotFinalized()\n return this.#nextOperatorId++\n }\n\n newInput<T>(): RootStreamBuilder<T> {\n this.#checkNotFinalized()\n const writer = new DifferenceStreamWriter<T>()\n // Use the root stream builder that exposes the sendData and sendFrontier methods\n const streamBuilder = new RootStreamBuilder<T>(this, writer)\n this.#streams.push(streamBuilder.connectReader())\n return streamBuilder\n }\n\n addOperator(operator: UnaryOperator<any> | BinaryOperator<any>): void {\n this.#checkNotFinalized()\n this.#operators.push(operator)\n }\n\n addStream(stream: DifferenceStreamReader<any>): void {\n this.#checkNotFinalized()\n this.#streams.push(stream)\n }\n\n finalize() {\n this.#checkNotFinalized()\n this.#finalized = true\n }\n\n step(): void {\n if (!this.#finalized) {\n throw new Error(`Graph not finalized`)\n }\n for (const op of this.#operators) {\n op.run()\n }\n }\n\n pendingWork(): boolean {\n return this.#operators.some((op) => op.hasPendingWork())\n }\n\n run(): void {\n while (this.pendingWork()) {\n this.step()\n }\n }\n}\n\nexport class StreamBuilder<T> implements IStreamBuilder<T> {\n #graph: ID2\n #writer: DifferenceStreamWriter<T>\n\n constructor(graph: ID2, writer: DifferenceStreamWriter<T>) {\n this.#graph = graph\n this.#writer = writer\n }\n\n connectReader(): DifferenceStreamReader<T> {\n return this.#writer.newReader()\n }\n\n get writer(): DifferenceStreamWriter<T> {\n return this.#writer\n }\n\n get graph(): ID2 {\n return this.#graph\n }\n\n // Don't judge, this is the only way to type this function.\n // rxjs has very similar code to type its pipe function\n // https://github.com/ReactiveX/rxjs/blob/master/packages/rxjs/src/internal/util/pipe.ts\n // We go to 20 operators deep, because surly that's enough for anyone...\n // A user can always split the pipe into multiple pipes to get around this.\n pipe<O>(o1: PipedOperator<T, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, T16>, o16: PipedOperator<T16, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, T16>, o16: PipedOperator<T16, T17>, o17: PipedOperator<T17, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, T16>, o16: PipedOperator<T16, T17>, o17: PipedOperator<T17, T18>, o18: PipedOperator<T18, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, T16>, o16: PipedOperator<T16, T17>, o17: PipedOperator<T17, T18>, o18: PipedOperator<T18, T19>, o19: PipedOperator<T19, O>): IStreamBuilder<O>\n // prettier-ignore\n pipe<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, T5>, o5: PipedOperator<T5, T6>, o6: PipedOperator<T6, T7>, o7: PipedOperator<T7, T8>, o8: PipedOperator<T8, T9>, o9: PipedOperator<T9, T10>, o10: PipedOperator<T10, T11>, o11: PipedOperator<T11, T12>, o12: PipedOperator<T12, T13>, o13: PipedOperator<T13, T14>, o14: PipedOperator<T14, T15>, o15: PipedOperator<T15, T16>, o16: PipedOperator<T16, T17>, o17: PipedOperator<T17, T18>, o18: PipedOperator<T18, T19>, o19: PipedOperator<T19, T20>, o20: PipedOperator<T20, O>): IStreamBuilder<O>\n\n pipe(...operators: Array<PipedOperator<any, any>>): IStreamBuilder<any> {\n return operators.reduce((stream, operator) => {\n return operator(stream)\n }, this as IStreamBuilder<any>)\n }\n}\n\nexport class RootStreamBuilder<T> extends StreamBuilder<T> {\n sendData(collection: MultiSet<T> | MultiSetArray<T>): void {\n this.writer.sendData(collection)\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AASO,MAAM,GAAkB;AAAA,EAM7B,cAAc;AANT;AACL,iCAA+C,CAAA;AAC/C,mCAA8D,CAAA;AAC9D,wCAAkB;AAClB,mCAAa;AAAA,EAEE;AAAA,EAQf,oBAA4B;AAC1B,0BAAK,qCAAL;AACA,WAAO,uBAAK,iBAAL;AAAA,EACT;AAAA,EAEA,WAAoC;AAClC,0BAAK,qCAAL;AACA,UAAM,SAAS,IAAI,uBAAA;AAEnB,UAAM,gBAAgB,IAAI,kBAAqB,MAAM,MAAM;AAC3D,uBAAK,UAAS,KAAK,cAAc,cAAA,CAAe;AAChD,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,UAA0D;AACpE,0BAAK,qCAAL;AACA,uBAAK,YAAW,KAAK,QAAQ;AAAA,EAC/B;AAAA,EAEA,UAAU,QAA2C;AACnD,0BAAK,qCAAL;AACA,uBAAK,UAAS,KAAK,MAAM;AAAA,EAC3B;AAAA,EAEA,WAAW;AACT,0BAAK,qCAAL;AACA,uBAAK,YAAa;AAAA,EACpB;AAAA,EAEA,OAAa;AACX,QAAI,CAAC,mBAAK,aAAY;AACpB,YAAM,IAAI,MAAM,qBAAqB;AAAA,IACvC;AACA,eAAW,MAAM,mBAAK,aAAY;AAChC,SAAG,IAAA;AAAA,IACL;AAAA,EACF;AAAA,EAEA,cAAuB;AACrB,WAAO,mBAAK,YAAW,KAAK,CAAC,OAAO,GAAG,gBAAgB;AAAA,EACzD;AAAA,EAEA,MAAY;AACV,WAAO,KAAK,eAAe;AACzB,WAAK,KAAA;AAAA,IACP;AAAA,EACF;AACF;AA5DE;AACA;AACA;AACA;AAJK;AAQL,uBAAA,WAA2B;AACzB,MAAI,mBAAK,aAAY;AACnB,UAAM,IAAI,MAAM,yBAAyB;AAAA,EAC3C;AACF;AAmDK,MAAM,cAA8C;AAAA,EAIzD,YAAY,OAAY,QAAmC;AAH3D;AACA;AAGE,uBAAK,QAAS;AACd,uBAAK,SAAU;AAAA,EACjB;AAAA,EAEA,gBAA2C;AACzC,WAAO,mBAAK,SAAQ,UAAA;AAAA,EACtB;AAAA,EAEA,IAAI,SAAoC;AACtC,WAAO,mBAAK;AAAA,EACd;AAAA,EAEA,IAAI,QAAa;AACf,WAAO,mBAAK;AAAA,EACd;AAAA,EA+CA,QAAQ,WAAgE;AACtE,WAAO,UAAU,OAAO,CAAC,QAAQ,aAAa;AAC5C,aAAO,SAAS,MAAM;AAAA,IACxB,GAAG,IAA2B;AAAA,EAChC;AACF;AAtEE;AACA;AAuEK,MAAM,0BAA6B,cAAiB;AAAA,EACzD,SAAS,YAAkD;AACzD,SAAK,OAAO,SAAS,UAAU;AAAA,EACjC;AACF;"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { MultiSet, MultiSetArray } from './multiset.js';
|
|
2
|
+
import { IDifferenceStreamReader, IDifferenceStreamWriter, IOperator } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* A read handle to a dataflow edge that receives data from a writer.
|
|
5
|
+
*/
|
|
6
|
+
export declare class DifferenceStreamReader<T> implements IDifferenceStreamReader<T> {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(queue: Array<MultiSet<T>>);
|
|
9
|
+
drain(): Array<MultiSet<T>>;
|
|
10
|
+
isEmpty(): boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A write handle to a dataflow edge that is allowed to publish data.
|
|
14
|
+
*/
|
|
15
|
+
export declare class DifferenceStreamWriter<T> implements IDifferenceStreamWriter<T> {
|
|
16
|
+
#private;
|
|
17
|
+
sendData(collection: MultiSet<T> | MultiSetArray<T>): void;
|
|
18
|
+
newReader(): DifferenceStreamReader<T>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A generic implementation of a dataflow operator (node) that has multiple incoming edges (read handles) and
|
|
22
|
+
* one outgoing edge (write handle).
|
|
23
|
+
*/
|
|
24
|
+
export declare abstract class Operator<T> implements IOperator<T> {
|
|
25
|
+
id: number;
|
|
26
|
+
protected inputs: Array<DifferenceStreamReader<T>>;
|
|
27
|
+
protected output: DifferenceStreamWriter<T>;
|
|
28
|
+
constructor(id: number, inputs: Array<DifferenceStreamReader<T>>, output: DifferenceStreamWriter<T>);
|
|
29
|
+
abstract run(): void;
|
|
30
|
+
hasPendingWork(): boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A convenience implementation of a dataflow operator that has a handle to one
|
|
34
|
+
* incoming stream of data, and one handle to an outgoing stream of data.
|
|
35
|
+
*/
|
|
36
|
+
export declare abstract class UnaryOperator<Tin, Tout = Tin> extends Operator<Tin | Tout> {
|
|
37
|
+
id: number;
|
|
38
|
+
constructor(id: number, inputA: DifferenceStreamReader<Tin>, output: DifferenceStreamWriter<Tout>);
|
|
39
|
+
inputMessages(): Array<MultiSet<Tin>>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A convenience implementation of a dataflow operator that has a handle to two
|
|
43
|
+
* incoming streams of data, and one handle to an outgoing stream of data.
|
|
44
|
+
*/
|
|
45
|
+
export declare abstract class BinaryOperator<T> extends Operator<T> {
|
|
46
|
+
id: number;
|
|
47
|
+
constructor(id: number, inputA: DifferenceStreamReader<T>, inputB: DifferenceStreamReader<T>, output: DifferenceStreamWriter<T>);
|
|
48
|
+
inputAMessages(): Array<MultiSet<T>>;
|
|
49
|
+
inputBMessages(): Array<MultiSet<T>>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Base class for operators that process a single input stream
|
|
53
|
+
*/
|
|
54
|
+
export declare abstract class LinearUnaryOperator<T, U> extends UnaryOperator<T | U> {
|
|
55
|
+
abstract inner(collection: MultiSet<T | U>): MultiSet<U>;
|
|
56
|
+
run(): void;
|
|
57
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var _queue, _queues;
|
|
9
|
+
import { MultiSet } from "./multiset.js";
|
|
10
|
+
class DifferenceStreamReader {
|
|
11
|
+
constructor(queue) {
|
|
12
|
+
__privateAdd(this, _queue);
|
|
13
|
+
__privateSet(this, _queue, queue);
|
|
14
|
+
}
|
|
15
|
+
drain() {
|
|
16
|
+
const out = [...__privateGet(this, _queue)].reverse();
|
|
17
|
+
__privateGet(this, _queue).length = 0;
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
isEmpty() {
|
|
21
|
+
return __privateGet(this, _queue).length === 0;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
_queue = new WeakMap();
|
|
25
|
+
class DifferenceStreamWriter {
|
|
26
|
+
constructor() {
|
|
27
|
+
__privateAdd(this, _queues, []);
|
|
28
|
+
}
|
|
29
|
+
sendData(collection) {
|
|
30
|
+
if (!(collection instanceof MultiSet)) {
|
|
31
|
+
collection = new MultiSet(collection);
|
|
32
|
+
}
|
|
33
|
+
for (const q of __privateGet(this, _queues)) {
|
|
34
|
+
q.unshift(collection);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
newReader() {
|
|
38
|
+
const q = [];
|
|
39
|
+
__privateGet(this, _queues).push(q);
|
|
40
|
+
return new DifferenceStreamReader(q);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
_queues = new WeakMap();
|
|
44
|
+
class Operator {
|
|
45
|
+
constructor(id, inputs, output) {
|
|
46
|
+
this.id = id;
|
|
47
|
+
this.inputs = inputs;
|
|
48
|
+
this.output = output;
|
|
49
|
+
}
|
|
50
|
+
hasPendingWork() {
|
|
51
|
+
return this.inputs.some((input) => !input.isEmpty());
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
class UnaryOperator extends Operator {
|
|
55
|
+
constructor(id, inputA, output) {
|
|
56
|
+
super(id, [inputA], output);
|
|
57
|
+
this.id = id;
|
|
58
|
+
}
|
|
59
|
+
inputMessages() {
|
|
60
|
+
return this.inputs[0].drain();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
class BinaryOperator extends Operator {
|
|
64
|
+
constructor(id, inputA, inputB, output) {
|
|
65
|
+
super(id, [inputA, inputB], output);
|
|
66
|
+
this.id = id;
|
|
67
|
+
}
|
|
68
|
+
inputAMessages() {
|
|
69
|
+
return this.inputs[0].drain();
|
|
70
|
+
}
|
|
71
|
+
inputBMessages() {
|
|
72
|
+
return this.inputs[1].drain();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
class LinearUnaryOperator extends UnaryOperator {
|
|
76
|
+
run() {
|
|
77
|
+
for (const message of this.inputMessages()) {
|
|
78
|
+
this.output.sendData(this.inner(message));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export {
|
|
83
|
+
BinaryOperator,
|
|
84
|
+
DifferenceStreamReader,
|
|
85
|
+
DifferenceStreamWriter,
|
|
86
|
+
LinearUnaryOperator,
|
|
87
|
+
Operator,
|
|
88
|
+
UnaryOperator
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.js","sources":["../../src/graph.ts"],"sourcesContent":["import { MultiSet } from \"./multiset.js\"\nimport type { MultiSetArray } from \"./multiset.js\"\nimport type {\n IDifferenceStreamReader,\n IDifferenceStreamWriter,\n IOperator,\n} from \"./types.js\"\n\n/**\n * A read handle to a dataflow edge that receives data from a writer.\n */\nexport class DifferenceStreamReader<T> implements IDifferenceStreamReader<T> {\n #queue: Array<MultiSet<T>>\n\n constructor(queue: Array<MultiSet<T>>) {\n this.#queue = queue\n }\n\n drain(): Array<MultiSet<T>> {\n const out = [...this.#queue].reverse()\n this.#queue.length = 0\n return out\n }\n\n isEmpty(): boolean {\n return this.#queue.length === 0\n }\n}\n\n/**\n * A write handle to a dataflow edge that is allowed to publish data.\n */\nexport class DifferenceStreamWriter<T> implements IDifferenceStreamWriter<T> {\n #queues: Array<Array<MultiSet<T>>> = []\n\n sendData(collection: MultiSet<T> | MultiSetArray<T>): void {\n if (!(collection instanceof MultiSet)) {\n collection = new MultiSet(collection)\n }\n\n for (const q of this.#queues) {\n q.unshift(collection)\n }\n }\n\n newReader(): DifferenceStreamReader<T> {\n const q: Array<MultiSet<T>> = []\n this.#queues.push(q)\n return new DifferenceStreamReader(q)\n }\n}\n\n/**\n * A generic implementation of a dataflow operator (node) that has multiple incoming edges (read handles) and\n * one outgoing edge (write handle).\n */\nexport abstract class Operator<T> implements IOperator<T> {\n protected inputs: Array<DifferenceStreamReader<T>>\n protected output: DifferenceStreamWriter<T>\n\n constructor(\n public id: number,\n inputs: Array<DifferenceStreamReader<T>>,\n output: DifferenceStreamWriter<T>\n ) {\n this.inputs = inputs\n this.output = output\n }\n\n abstract run(): void\n\n hasPendingWork(): boolean {\n return this.inputs.some((input) => !input.isEmpty())\n }\n}\n\n/**\n * A convenience implementation of a dataflow operator that has a handle to one\n * incoming stream of data, and one handle to an outgoing stream of data.\n */\nexport abstract class UnaryOperator<Tin, Tout = Tin> extends Operator<\n Tin | Tout\n> {\n constructor(\n public id: number,\n inputA: DifferenceStreamReader<Tin>,\n output: DifferenceStreamWriter<Tout>\n ) {\n super(id, [inputA], output)\n }\n\n inputMessages(): Array<MultiSet<Tin>> {\n return this.inputs[0]!.drain() as Array<MultiSet<Tin>>\n }\n}\n\n/**\n * A convenience implementation of a dataflow operator that has a handle to two\n * incoming streams of data, and one handle to an outgoing stream of data.\n */\nexport abstract class BinaryOperator<T> extends Operator<T> {\n constructor(\n public id: number,\n inputA: DifferenceStreamReader<T>,\n inputB: DifferenceStreamReader<T>,\n output: DifferenceStreamWriter<T>\n ) {\n super(id, [inputA, inputB], output)\n }\n\n inputAMessages(): Array<MultiSet<T>> {\n return this.inputs[0]!.drain()\n }\n\n inputBMessages(): Array<MultiSet<T>> {\n return this.inputs[1]!.drain()\n }\n}\n\n/**\n * Base class for operators that process a single input stream\n */\nexport abstract class LinearUnaryOperator<T, U> extends UnaryOperator<T | U> {\n abstract inner(collection: MultiSet<T | U>): MultiSet<U>\n\n run(): void {\n for (const message of this.inputMessages()) {\n this.output.sendData(this.inner(message))\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AAWO,MAAM,uBAAgE;AAAA,EAG3E,YAAY,OAA2B;AAFvC;AAGE,uBAAK,QAAS;AAAA,EAChB;AAAA,EAEA,QAA4B;AAC1B,UAAM,MAAM,CAAC,GAAG,mBAAK,OAAM,EAAE,QAAA;AAC7B,uBAAK,QAAO,SAAS;AACrB,WAAO;AAAA,EACT;AAAA,EAEA,UAAmB;AACjB,WAAO,mBAAK,QAAO,WAAW;AAAA,EAChC;AACF;AAfE;AAoBK,MAAM,uBAAgE;AAAA,EAAtE;AACL,gCAAqC,CAAA;AAAA;AAAA,EAErC,SAAS,YAAkD;AACzD,QAAI,EAAE,sBAAsB,WAAW;AACrC,mBAAa,IAAI,SAAS,UAAU;AAAA,IACtC;AAEA,eAAW,KAAK,mBAAK,UAAS;AAC5B,QAAE,QAAQ,UAAU;AAAA,IACtB;AAAA,EACF;AAAA,EAEA,YAAuC;AACrC,UAAM,IAAwB,CAAA;AAC9B,uBAAK,SAAQ,KAAK,CAAC;AACnB,WAAO,IAAI,uBAAuB,CAAC;AAAA,EACrC;AACF;AAjBE;AAuBK,MAAe,SAAoC;AAAA,EAIxD,YACS,IACP,QACA,QACA;AAHO,SAAA,KAAA;AAIP,SAAK,SAAS;AACd,SAAK,SAAS;AAAA,EAChB;AAAA,EAIA,iBAA0B;AACxB,WAAO,KAAK,OAAO,KAAK,CAAC,UAAU,CAAC,MAAM,SAAS;AAAA,EACrD;AACF;AAMO,MAAe,sBAAuC,SAE3D;AAAA,EACA,YACS,IACP,QACA,QACA;AACA,UAAM,IAAI,CAAC,MAAM,GAAG,MAAM;AAJnB,SAAA,KAAA;AAAA,EAKT;AAAA,EAEA,gBAAsC;AACpC,WAAO,KAAK,OAAO,CAAC,EAAG,MAAA;AAAA,EACzB;AACF;AAMO,MAAe,uBAA0B,SAAY;AAAA,EAC1D,YACS,IACP,QACA,QACA,QACA;AACA,UAAM,IAAI,CAAC,QAAQ,MAAM,GAAG,MAAM;AAL3B,SAAA,KAAA;AAAA,EAMT;AAAA,EAEA,iBAAqC;AACnC,WAAO,KAAK,OAAO,CAAC,EAAG,MAAA;AAAA,EACzB;AAAA,EAEA,iBAAqC;AACnC,WAAO,KAAK,OAAO,CAAC,EAAG,MAAA;AAAA,EACzB;AACF;AAKO,MAAe,4BAAkC,cAAqB;AAAA,EAG3E,MAAY;AACV,eAAW,WAAW,KAAK,iBAAiB;AAC1C,WAAK,OAAO,SAAS,KAAK,MAAM,OAAO,CAAC;AAAA,IAC1C;AAAA,EACF;AACF;"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { D2, RootStreamBuilder, StreamBuilder } from "./d2.js";
|
|
2
|
+
import { MultiSet } from "./multiset.js";
|
|
3
|
+
import { groupBy, groupByOperators } from "./operators/groupBy.js";
|
|
4
|
+
import { pipe } from "./operators/pipe.js";
|
|
5
|
+
import { MapOperator, map } from "./operators/map.js";
|
|
6
|
+
import { FilterOperator, filter } from "./operators/filter.js";
|
|
7
|
+
import { NegateOperator, negate } from "./operators/negate.js";
|
|
8
|
+
import { ConcatOperator, concat } from "./operators/concat.js";
|
|
9
|
+
import { DebugOperator, debug } from "./operators/debug.js";
|
|
10
|
+
import { OutputOperator, output } from "./operators/output.js";
|
|
11
|
+
import { ConsolidateOperator, consolidate } from "./operators/consolidate.js";
|
|
12
|
+
import { JoinOperator, antiJoin, fullJoin, innerJoin, join, leftJoin, rightJoin } from "./operators/join.js";
|
|
13
|
+
import { ReduceOperator, reduce } from "./operators/reduce.js";
|
|
14
|
+
import { CountOperator, count } from "./operators/count.js";
|
|
15
|
+
import { DistinctOperator, distinct } from "./operators/distinct.js";
|
|
16
|
+
import { keyBy, rekey, unkey } from "./operators/keying.js";
|
|
17
|
+
import { topK, topKWithIndex } from "./operators/topK.js";
|
|
18
|
+
import { TopKWithFractionalIndexOperator, getIndex, getValue, indexedValue, topKWithFractionalIndex } from "./operators/topKWithFractionalIndex.js";
|
|
19
|
+
import { orderBy, orderByWithFractionalIndex, orderByWithFractionalIndexBase, orderByWithIndex } from "./operators/orderBy.js";
|
|
20
|
+
import { filterBy } from "./operators/filterBy.js";
|
|
21
|
+
export {
|
|
22
|
+
ConcatOperator,
|
|
23
|
+
ConsolidateOperator,
|
|
24
|
+
CountOperator,
|
|
25
|
+
D2,
|
|
26
|
+
DebugOperator,
|
|
27
|
+
DistinctOperator,
|
|
28
|
+
FilterOperator,
|
|
29
|
+
JoinOperator,
|
|
30
|
+
MapOperator,
|
|
31
|
+
MultiSet,
|
|
32
|
+
NegateOperator,
|
|
33
|
+
OutputOperator,
|
|
34
|
+
ReduceOperator,
|
|
35
|
+
RootStreamBuilder,
|
|
36
|
+
StreamBuilder,
|
|
37
|
+
TopKWithFractionalIndexOperator,
|
|
38
|
+
antiJoin,
|
|
39
|
+
concat,
|
|
40
|
+
consolidate,
|
|
41
|
+
count,
|
|
42
|
+
debug,
|
|
43
|
+
distinct,
|
|
44
|
+
filter,
|
|
45
|
+
filterBy,
|
|
46
|
+
fullJoin,
|
|
47
|
+
getIndex,
|
|
48
|
+
getValue,
|
|
49
|
+
groupBy,
|
|
50
|
+
groupByOperators,
|
|
51
|
+
indexedValue,
|
|
52
|
+
innerJoin,
|
|
53
|
+
join,
|
|
54
|
+
keyBy,
|
|
55
|
+
leftJoin,
|
|
56
|
+
map,
|
|
57
|
+
negate,
|
|
58
|
+
orderBy,
|
|
59
|
+
orderByWithFractionalIndex,
|
|
60
|
+
orderByWithFractionalIndexBase,
|
|
61
|
+
orderByWithIndex,
|
|
62
|
+
output,
|
|
63
|
+
pipe,
|
|
64
|
+
reduce,
|
|
65
|
+
rekey,
|
|
66
|
+
rightJoin,
|
|
67
|
+
topK,
|
|
68
|
+
topKWithFractionalIndex,
|
|
69
|
+
topKWithIndex,
|
|
70
|
+
unkey
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { MultiSet } from './multiset.js';
|
|
2
|
+
/**
|
|
3
|
+
* A map from a difference collection trace's keys -> (value, multiplicities) that changed.
|
|
4
|
+
* Used in operations like join and reduce where the operation needs to
|
|
5
|
+
* exploit the key-value structure of the data to run efficiently.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Index<K, V> {
|
|
8
|
+
#private;
|
|
9
|
+
constructor();
|
|
10
|
+
toString(indent?: boolean): string;
|
|
11
|
+
get(key: K): Array<[V, number]>;
|
|
12
|
+
getMultiplicity(key: K, value: V): number;
|
|
13
|
+
entries(): MapIterator<[K, Map<V, number>]>;
|
|
14
|
+
keys(): MapIterator<K>;
|
|
15
|
+
has(key: K): boolean;
|
|
16
|
+
get size(): number;
|
|
17
|
+
addValue(key: K, value: [V, number]): void;
|
|
18
|
+
append(other: Index<K, V>): void;
|
|
19
|
+
join<V2>(other: Index<K, V2>): MultiSet<[K, [V, V2]]>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var _inner;
|
|
9
|
+
import { MultiSet } from "./multiset.js";
|
|
10
|
+
import { DefaultMap } from "./utils.js";
|
|
11
|
+
class Index {
|
|
12
|
+
constructor() {
|
|
13
|
+
__privateAdd(this, _inner);
|
|
14
|
+
__privateSet(this, _inner, new DefaultMap(() => /* @__PURE__ */ new Map()));
|
|
15
|
+
}
|
|
16
|
+
toString(indent = false) {
|
|
17
|
+
return `Index(${JSON.stringify(
|
|
18
|
+
[...__privateGet(this, _inner)].map(([k, valueMap]) => [k, [...valueMap]]),
|
|
19
|
+
void 0,
|
|
20
|
+
indent ? ` ` : void 0
|
|
21
|
+
)})`;
|
|
22
|
+
}
|
|
23
|
+
get(key) {
|
|
24
|
+
const valueMap = __privateGet(this, _inner).get(key);
|
|
25
|
+
return [...valueMap.entries()];
|
|
26
|
+
}
|
|
27
|
+
getMultiplicity(key, value) {
|
|
28
|
+
const valueMap = __privateGet(this, _inner).get(key);
|
|
29
|
+
return valueMap.get(value) ?? 0;
|
|
30
|
+
}
|
|
31
|
+
entries() {
|
|
32
|
+
return __privateGet(this, _inner).entries();
|
|
33
|
+
}
|
|
34
|
+
keys() {
|
|
35
|
+
return __privateGet(this, _inner).keys();
|
|
36
|
+
}
|
|
37
|
+
has(key) {
|
|
38
|
+
return __privateGet(this, _inner).has(key);
|
|
39
|
+
}
|
|
40
|
+
get size() {
|
|
41
|
+
return __privateGet(this, _inner).size;
|
|
42
|
+
}
|
|
43
|
+
addValue(key, value) {
|
|
44
|
+
const [val, multiplicity] = value;
|
|
45
|
+
const valueMap = __privateGet(this, _inner).get(key);
|
|
46
|
+
const existingMultiplicity = valueMap.get(val) ?? 0;
|
|
47
|
+
const newMultiplicity = existingMultiplicity + multiplicity;
|
|
48
|
+
if (multiplicity !== 0) {
|
|
49
|
+
if (newMultiplicity === 0) {
|
|
50
|
+
valueMap.delete(val);
|
|
51
|
+
} else {
|
|
52
|
+
valueMap.set(val, newMultiplicity);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
append(other) {
|
|
57
|
+
for (const [key, otherValueMap] of other.entries()) {
|
|
58
|
+
const thisValueMap = __privateGet(this, _inner).get(key);
|
|
59
|
+
for (const [value, multiplicity] of otherValueMap.entries()) {
|
|
60
|
+
const existingMultiplicity = thisValueMap.get(value) ?? 0;
|
|
61
|
+
const newMultiplicity = existingMultiplicity + multiplicity;
|
|
62
|
+
if (newMultiplicity === 0) {
|
|
63
|
+
thisValueMap.delete(value);
|
|
64
|
+
} else {
|
|
65
|
+
thisValueMap.set(value, newMultiplicity);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
join(other) {
|
|
71
|
+
const result = [];
|
|
72
|
+
if (this.size <= other.size) {
|
|
73
|
+
for (const [key, valueMap] of this.entries()) {
|
|
74
|
+
if (!other.has(key)) continue;
|
|
75
|
+
const otherValues = other.get(key);
|
|
76
|
+
for (const [val1, mul1] of valueMap.entries()) {
|
|
77
|
+
for (const [val2, mul2] of otherValues) {
|
|
78
|
+
if (mul1 !== 0 && mul2 !== 0) {
|
|
79
|
+
result.push([[key, [val1, val2]], mul1 * mul2]);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
for (const [key, otherValueMap] of other.entries()) {
|
|
86
|
+
if (!this.has(key)) continue;
|
|
87
|
+
const values = this.get(key);
|
|
88
|
+
for (const [val2, mul2] of otherValueMap.entries()) {
|
|
89
|
+
for (const [val1, mul1] of values) {
|
|
90
|
+
if (mul1 !== 0 && mul2 !== 0) {
|
|
91
|
+
result.push([[key, [val1, val2]], mul1 * mul2]);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return new MultiSet(result);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
_inner = new WeakMap();
|
|
101
|
+
export {
|
|
102
|
+
Index
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=indexes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexes.js","sources":["../../src/indexes.ts"],"sourcesContent":["import { MultiSet } from \"./multiset.js\"\nimport { DefaultMap } from \"./utils.js\"\n\n/**\n * A map from a difference collection trace's keys -> (value, multiplicities) that changed.\n * Used in operations like join and reduce where the operation needs to\n * exploit the key-value structure of the data to run efficiently.\n */\nexport class Index<K, V> {\n #inner: DefaultMap<K, Map<V, number>>\n\n constructor() {\n this.#inner = new DefaultMap<K, Map<V, number>>(() => new Map<V, number>())\n // #inner is a map of:\n // {\n // [key]: Map<V, number> // Direct value-to-multiplicity mapping\n // }\n }\n\n toString(indent = false): string {\n return `Index(${JSON.stringify(\n [...this.#inner].map(([k, valueMap]) => [k, [...valueMap]]),\n undefined,\n indent ? ` ` : undefined\n )})`\n }\n\n get(key: K): Array<[V, number]> {\n const valueMap = this.#inner.get(key)\n return [...valueMap.entries()]\n }\n\n getMultiplicity(key: K, value: V): number {\n const valueMap = this.#inner.get(key)\n return valueMap.get(value) ?? 0\n }\n\n entries() {\n return this.#inner.entries()\n }\n\n keys() {\n return this.#inner.keys()\n }\n\n has(key: K): boolean {\n return this.#inner.has(key)\n }\n\n get size(): number {\n return this.#inner.size\n }\n\n addValue(key: K, value: [V, number]): void {\n const [val, multiplicity] = value\n const valueMap = this.#inner.get(key)\n const existingMultiplicity = valueMap.get(val) ?? 0\n const newMultiplicity = existingMultiplicity + multiplicity\n\n if (multiplicity !== 0) {\n if (newMultiplicity === 0) {\n valueMap.delete(val)\n } else {\n valueMap.set(val, newMultiplicity)\n }\n }\n }\n\n append(other: Index<K, V>): void {\n for (const [key, otherValueMap] of other.entries()) {\n const thisValueMap = this.#inner.get(key)\n for (const [value, multiplicity] of otherValueMap.entries()) {\n const existingMultiplicity = thisValueMap.get(value) ?? 0\n const newMultiplicity = existingMultiplicity + multiplicity\n if (newMultiplicity === 0) {\n thisValueMap.delete(value)\n } else {\n thisValueMap.set(value, newMultiplicity)\n }\n }\n }\n }\n\n join<V2>(other: Index<K, V2>): MultiSet<[K, [V, V2]]> {\n const result: Array<[[K, [V, V2]], number]> = []\n\n // We want to iterate over the smaller of the two indexes to reduce the\n // number of operations we need to do.\n if (this.size <= other.size) {\n for (const [key, valueMap] of this.entries()) {\n if (!other.has(key)) continue\n const otherValues = other.get(key)\n for (const [val1, mul1] of valueMap.entries()) {\n for (const [val2, mul2] of otherValues) {\n if (mul1 !== 0 && mul2 !== 0) {\n result.push([[key, [val1, val2]], mul1 * mul2])\n }\n }\n }\n }\n } else {\n for (const [key, otherValueMap] of other.entries()) {\n if (!this.has(key)) continue\n const values = this.get(key)\n for (const [val2, mul2] of otherValueMap.entries()) {\n for (const [val1, mul1] of values) {\n if (mul1 !== 0 && mul2 !== 0) {\n result.push([[key, [val1, val2]], mul1 * mul2])\n }\n }\n }\n }\n }\n\n return new MultiSet(result)\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAQO,MAAM,MAAY;AAAA,EAGvB,cAAc;AAFd;AAGE,uBAAK,QAAS,IAAI,WAA8B,MAAM,oBAAI,KAAgB;AAAA,EAK5E;AAAA,EAEA,SAAS,SAAS,OAAe;AAC/B,WAAO,SAAS,KAAK;AAAA,MACnB,CAAC,GAAG,mBAAK,OAAM,EAAE,IAAI,CAAC,CAAC,GAAG,QAAQ,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC;AAAA,MAC1D;AAAA,MACA,SAAS,OAAO;AAAA,IAAA,CACjB;AAAA,EACH;AAAA,EAEA,IAAI,KAA4B;AAC9B,UAAM,WAAW,mBAAK,QAAO,IAAI,GAAG;AACpC,WAAO,CAAC,GAAG,SAAS,SAAS;AAAA,EAC/B;AAAA,EAEA,gBAAgB,KAAQ,OAAkB;AACxC,UAAM,WAAW,mBAAK,QAAO,IAAI,GAAG;AACpC,WAAO,SAAS,IAAI,KAAK,KAAK;AAAA,EAChC;AAAA,EAEA,UAAU;AACR,WAAO,mBAAK,QAAO,QAAA;AAAA,EACrB;AAAA,EAEA,OAAO;AACL,WAAO,mBAAK,QAAO,KAAA;AAAA,EACrB;AAAA,EAEA,IAAI,KAAiB;AACnB,WAAO,mBAAK,QAAO,IAAI,GAAG;AAAA,EAC5B;AAAA,EAEA,IAAI,OAAe;AACjB,WAAO,mBAAK,QAAO;AAAA,EACrB;AAAA,EAEA,SAAS,KAAQ,OAA0B;AACzC,UAAM,CAAC,KAAK,YAAY,IAAI;AAC5B,UAAM,WAAW,mBAAK,QAAO,IAAI,GAAG;AACpC,UAAM,uBAAuB,SAAS,IAAI,GAAG,KAAK;AAClD,UAAM,kBAAkB,uBAAuB;AAE/C,QAAI,iBAAiB,GAAG;AACtB,UAAI,oBAAoB,GAAG;AACzB,iBAAS,OAAO,GAAG;AAAA,MACrB,OAAO;AACL,iBAAS,IAAI,KAAK,eAAe;AAAA,MACnC;AAAA,IACF;AAAA,EACF;AAAA,EAEA,OAAO,OAA0B;AAC/B,eAAW,CAAC,KAAK,aAAa,KAAK,MAAM,WAAW;AAClD,YAAM,eAAe,mBAAK,QAAO,IAAI,GAAG;AACxC,iBAAW,CAAC,OAAO,YAAY,KAAK,cAAc,WAAW;AAC3D,cAAM,uBAAuB,aAAa,IAAI,KAAK,KAAK;AACxD,cAAM,kBAAkB,uBAAuB;AAC/C,YAAI,oBAAoB,GAAG;AACzB,uBAAa,OAAO,KAAK;AAAA,QAC3B,OAAO;AACL,uBAAa,IAAI,OAAO,eAAe;AAAA,QACzC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,KAAS,OAA6C;AACpD,UAAM,SAAwC,CAAA;AAI9C,QAAI,KAAK,QAAQ,MAAM,MAAM;AAC3B,iBAAW,CAAC,KAAK,QAAQ,KAAK,KAAK,WAAW;AAC5C,YAAI,CAAC,MAAM,IAAI,GAAG,EAAG;AACrB,cAAM,cAAc,MAAM,IAAI,GAAG;AACjC,mBAAW,CAAC,MAAM,IAAI,KAAK,SAAS,WAAW;AAC7C,qBAAW,CAAC,MAAM,IAAI,KAAK,aAAa;AACtC,gBAAI,SAAS,KAAK,SAAS,GAAG;AAC5B,qBAAO,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,GAAG,OAAO,IAAI,CAAC;AAAA,YAChD;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF,OAAO;AACL,iBAAW,CAAC,KAAK,aAAa,KAAK,MAAM,WAAW;AAClD,YAAI,CAAC,KAAK,IAAI,GAAG,EAAG;AACpB,cAAM,SAAS,KAAK,IAAI,GAAG;AAC3B,mBAAW,CAAC,MAAM,IAAI,KAAK,cAAc,WAAW;AAClD,qBAAW,CAAC,MAAM,IAAI,KAAK,QAAQ;AACjC,gBAAI,SAAS,KAAK,SAAS,GAAG;AAC5B,qBAAO,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,GAAG,OAAO,IAAI,CAAC;AAAA,YAChD;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO,IAAI,SAAS,MAAM;AAAA,EAC5B;AACF;AA3GE;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type MultiSetArray<T> = Array<[T, number]>;
|
|
2
|
+
export type KeyedData<T> = [key: string, value: T];
|
|
3
|
+
/**
|
|
4
|
+
* A multiset of data.
|
|
5
|
+
*/
|
|
6
|
+
export declare class MultiSet<T> {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(data?: MultiSetArray<T>);
|
|
9
|
+
toString(indent?: boolean): string;
|
|
10
|
+
toJSON(): string;
|
|
11
|
+
static fromJSON<U>(json: string): MultiSet<U>;
|
|
12
|
+
/**
|
|
13
|
+
* Apply a function to all records in the collection.
|
|
14
|
+
*/
|
|
15
|
+
map<U>(f: (data: T) => U): MultiSet<U>;
|
|
16
|
+
/**
|
|
17
|
+
* Filter out records for which a function f(record) evaluates to False.
|
|
18
|
+
*/
|
|
19
|
+
filter(f: (data: T) => boolean): MultiSet<T>;
|
|
20
|
+
/**
|
|
21
|
+
* Negate all multiplicities in the collection.
|
|
22
|
+
*/
|
|
23
|
+
negate(): MultiSet<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Concatenate two collections together.
|
|
26
|
+
*/
|
|
27
|
+
concat(other: MultiSet<T>): MultiSet<T>;
|
|
28
|
+
/**
|
|
29
|
+
* Produce as output a collection that is logically equivalent to the input
|
|
30
|
+
* but which combines identical instances of the same record into one
|
|
31
|
+
* (record, multiplicity) pair.
|
|
32
|
+
*/
|
|
33
|
+
consolidate(): MultiSet<T>;
|
|
34
|
+
extend(other: MultiSet<T> | MultiSetArray<T>): void;
|
|
35
|
+
getInner(): MultiSetArray<T>;
|
|
36
|
+
}
|