@tanstack/db-ivm 0.0.0 → 0.1.0

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.
Files changed (154) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/d2.cjs +111 -0
  3. package/dist/cjs/d2.cjs.map +1 -0
  4. package/dist/cjs/d2.d.cts +45 -0
  5. package/dist/cjs/graph.cjs +90 -0
  6. package/dist/cjs/graph.cjs.map +1 -0
  7. package/dist/cjs/graph.d.cts +57 -0
  8. package/dist/cjs/index.cjs +72 -0
  9. package/dist/cjs/index.cjs.map +1 -0
  10. package/dist/cjs/index.d.cts +4 -0
  11. package/dist/cjs/indexes.cjs +104 -0
  12. package/dist/cjs/indexes.cjs.map +1 -0
  13. package/dist/cjs/indexes.d.cts +20 -0
  14. package/dist/cjs/multiset.cjs +173 -0
  15. package/dist/cjs/multiset.cjs.map +1 -0
  16. package/dist/cjs/multiset.d.cts +36 -0
  17. package/dist/cjs/operators/concat.cjs +37 -0
  18. package/dist/cjs/operators/concat.cjs.map +1 -0
  19. package/dist/cjs/operators/concat.d.cts +13 -0
  20. package/dist/cjs/operators/consolidate.cjs +40 -0
  21. package/dist/cjs/operators/consolidate.cjs.map +1 -0
  22. package/dist/cjs/operators/consolidate.d.cts +12 -0
  23. package/dist/cjs/operators/count.cjs +36 -0
  24. package/dist/cjs/operators/count.cjs.map +1 -0
  25. package/dist/cjs/operators/count.d.cts +13 -0
  26. package/dist/cjs/operators/debug.cjs +50 -0
  27. package/dist/cjs/operators/debug.cjs.map +1 -0
  28. package/dist/cjs/operators/debug.d.cts +16 -0
  29. package/dist/cjs/operators/distinct.cjs +78 -0
  30. package/dist/cjs/operators/distinct.cjs.map +1 -0
  31. package/dist/cjs/operators/distinct.d.cts +14 -0
  32. package/dist/cjs/operators/filter.cjs +43 -0
  33. package/dist/cjs/operators/filter.cjs.map +1 -0
  34. package/dist/cjs/operators/filter.d.cts +16 -0
  35. package/dist/cjs/operators/filterBy.cjs +19 -0
  36. package/dist/cjs/operators/filterBy.cjs.map +1 -0
  37. package/dist/cjs/operators/filterBy.d.cts +10 -0
  38. package/dist/cjs/operators/groupBy.cjs +225 -0
  39. package/dist/cjs/operators/groupBy.cjs.map +1 -0
  40. package/dist/cjs/operators/groupBy.d.cts +68 -0
  41. package/dist/cjs/operators/index.d.cts +18 -0
  42. package/dist/cjs/operators/join.cjs +145 -0
  43. package/dist/cjs/operators/join.cjs.map +1 -0
  44. package/dist/cjs/operators/join.d.cts +48 -0
  45. package/dist/cjs/operators/keying.cjs +16 -0
  46. package/dist/cjs/operators/keying.cjs.map +1 -0
  47. package/dist/cjs/operators/keying.d.cts +19 -0
  48. package/dist/cjs/operators/map.cjs +43 -0
  49. package/dist/cjs/operators/map.cjs.map +1 -0
  50. package/dist/cjs/operators/map.d.cts +16 -0
  51. package/dist/cjs/operators/negate.cjs +28 -0
  52. package/dist/cjs/operators/negate.cjs.map +1 -0
  53. package/dist/cjs/operators/negate.d.cts +13 -0
  54. package/dist/cjs/operators/orderBy.cjs +115 -0
  55. package/dist/cjs/operators/orderBy.cjs.map +1 -0
  56. package/dist/cjs/operators/orderBy.d.cts +38 -0
  57. package/dist/cjs/operators/orderByBTree.d.cts +3 -0
  58. package/dist/cjs/operators/output.cjs +46 -0
  59. package/dist/cjs/operators/output.cjs.map +1 -0
  60. package/dist/cjs/operators/output.d.cts +16 -0
  61. package/dist/cjs/operators/pipe.cjs +9 -0
  62. package/dist/cjs/operators/pipe.cjs.map +1 -0
  63. package/dist/cjs/operators/pipe.d.cts +21 -0
  64. package/dist/cjs/operators/reduce.cjs +99 -0
  65. package/dist/cjs/operators/reduce.cjs.map +1 -0
  66. package/dist/cjs/operators/reduce.d.cts +14 -0
  67. package/dist/cjs/operators/topK.cjs +39 -0
  68. package/dist/cjs/operators/topK.cjs.map +1 -0
  69. package/dist/cjs/operators/topK.d.cts +32 -0
  70. package/dist/cjs/operators/topKWithFractionalIndex.cjs +201 -0
  71. package/dist/cjs/operators/topKWithFractionalIndex.cjs.map +1 -0
  72. package/dist/cjs/operators/topKWithFractionalIndex.d.cts +61 -0
  73. package/dist/cjs/operators/topKWithFractionalIndexBTree.d.cts +27 -0
  74. package/dist/cjs/types.d.cts +30 -0
  75. package/dist/cjs/utils.cjs +125 -0
  76. package/dist/cjs/utils.cjs.map +1 -0
  77. package/dist/cjs/utils.d.cts +40 -0
  78. package/dist/esm/d2.d.ts +45 -0
  79. package/dist/esm/d2.js +111 -0
  80. package/dist/esm/d2.js.map +1 -0
  81. package/dist/esm/graph.d.ts +57 -0
  82. package/dist/esm/graph.js +90 -0
  83. package/dist/esm/graph.js.map +1 -0
  84. package/dist/esm/index.d.ts +4 -0
  85. package/dist/esm/index.js +72 -0
  86. package/dist/esm/index.js.map +1 -0
  87. package/dist/esm/indexes.d.ts +20 -0
  88. package/dist/esm/indexes.js +104 -0
  89. package/dist/esm/indexes.js.map +1 -0
  90. package/dist/esm/multiset.d.ts +36 -0
  91. package/dist/esm/multiset.js +173 -0
  92. package/dist/esm/multiset.js.map +1 -0
  93. package/dist/esm/operators/concat.d.ts +13 -0
  94. package/dist/esm/operators/concat.js +37 -0
  95. package/dist/esm/operators/concat.js.map +1 -0
  96. package/dist/esm/operators/consolidate.d.ts +12 -0
  97. package/dist/esm/operators/consolidate.js +40 -0
  98. package/dist/esm/operators/consolidate.js.map +1 -0
  99. package/dist/esm/operators/count.d.ts +13 -0
  100. package/dist/esm/operators/count.js +36 -0
  101. package/dist/esm/operators/count.js.map +1 -0
  102. package/dist/esm/operators/debug.d.ts +16 -0
  103. package/dist/esm/operators/debug.js +50 -0
  104. package/dist/esm/operators/debug.js.map +1 -0
  105. package/dist/esm/operators/distinct.d.ts +14 -0
  106. package/dist/esm/operators/distinct.js +78 -0
  107. package/dist/esm/operators/distinct.js.map +1 -0
  108. package/dist/esm/operators/filter.d.ts +16 -0
  109. package/dist/esm/operators/filter.js +43 -0
  110. package/dist/esm/operators/filter.js.map +1 -0
  111. package/dist/esm/operators/filterBy.d.ts +10 -0
  112. package/dist/esm/operators/filterBy.js +19 -0
  113. package/dist/esm/operators/filterBy.js.map +1 -0
  114. package/dist/esm/operators/groupBy.d.ts +68 -0
  115. package/dist/esm/operators/groupBy.js +225 -0
  116. package/dist/esm/operators/groupBy.js.map +1 -0
  117. package/dist/esm/operators/index.d.ts +18 -0
  118. package/dist/esm/operators/join.d.ts +48 -0
  119. package/dist/esm/operators/join.js +145 -0
  120. package/dist/esm/operators/join.js.map +1 -0
  121. package/dist/esm/operators/keying.d.ts +19 -0
  122. package/dist/esm/operators/keying.js +16 -0
  123. package/dist/esm/operators/keying.js.map +1 -0
  124. package/dist/esm/operators/map.d.ts +16 -0
  125. package/dist/esm/operators/map.js +43 -0
  126. package/dist/esm/operators/map.js.map +1 -0
  127. package/dist/esm/operators/negate.d.ts +13 -0
  128. package/dist/esm/operators/negate.js +28 -0
  129. package/dist/esm/operators/negate.js.map +1 -0
  130. package/dist/esm/operators/orderBy.d.ts +38 -0
  131. package/dist/esm/operators/orderBy.js +115 -0
  132. package/dist/esm/operators/orderBy.js.map +1 -0
  133. package/dist/esm/operators/orderByBTree.d.ts +3 -0
  134. package/dist/esm/operators/output.d.ts +16 -0
  135. package/dist/esm/operators/output.js +46 -0
  136. package/dist/esm/operators/output.js.map +1 -0
  137. package/dist/esm/operators/pipe.d.ts +21 -0
  138. package/dist/esm/operators/pipe.js +9 -0
  139. package/dist/esm/operators/pipe.js.map +1 -0
  140. package/dist/esm/operators/reduce.d.ts +14 -0
  141. package/dist/esm/operators/reduce.js +99 -0
  142. package/dist/esm/operators/reduce.js.map +1 -0
  143. package/dist/esm/operators/topK.d.ts +32 -0
  144. package/dist/esm/operators/topK.js +39 -0
  145. package/dist/esm/operators/topK.js.map +1 -0
  146. package/dist/esm/operators/topKWithFractionalIndex.d.ts +61 -0
  147. package/dist/esm/operators/topKWithFractionalIndex.js +201 -0
  148. package/dist/esm/operators/topKWithFractionalIndex.js.map +1 -0
  149. package/dist/esm/operators/topKWithFractionalIndexBTree.d.ts +27 -0
  150. package/dist/esm/types.d.ts +30 -0
  151. package/dist/esm/utils.d.ts +40 -0
  152. package/dist/esm/utils.js +125 -0
  153. package/dist/esm/utils.js.map +1 -0
  154. package/package.json +6 -7
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __typeError = (msg) => {
3
+ throw TypeError(msg);
4
+ };
5
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
6
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
7
+ 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);
8
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
9
+ var _f;
10
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
11
+ const graph = require("../graph.cjs");
12
+ const d2 = require("../d2.cjs");
13
+ class MapOperator extends graph.LinearUnaryOperator {
14
+ constructor(id, inputA, output, f) {
15
+ super(id, inputA, output);
16
+ __privateAdd(this, _f);
17
+ __privateSet(this, _f, f);
18
+ }
19
+ inner(collection) {
20
+ return collection.map(__privateGet(this, _f));
21
+ }
22
+ }
23
+ _f = new WeakMap();
24
+ function map(f) {
25
+ return (stream) => {
26
+ const output = new d2.StreamBuilder(
27
+ stream.graph,
28
+ new graph.DifferenceStreamWriter()
29
+ );
30
+ const operator = new MapOperator(
31
+ stream.graph.getNextOperatorId(),
32
+ stream.connectReader(),
33
+ output.writer,
34
+ f
35
+ );
36
+ stream.graph.addOperator(operator);
37
+ stream.graph.addStream(output.connectReader());
38
+ return output;
39
+ };
40
+ }
41
+ exports.MapOperator = MapOperator;
42
+ exports.map = map;
43
+ //# sourceMappingURL=map.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map.cjs","sources":["../../../src/operators/map.ts"],"sourcesContent":["import { DifferenceStreamWriter, LinearUnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\nimport type { MultiSet } from \"../multiset.js\"\n\n/**\n * Operator that applies a function to each element in the input stream\n */\nexport class MapOperator<T, U> extends LinearUnaryOperator<T, U> {\n #f: (data: T) => U\n\n constructor(\n id: number,\n inputA: DifferenceStreamReader<T>,\n output: DifferenceStreamWriter<U>,\n f: (data: T) => U\n ) {\n super(id, inputA, output)\n this.#f = f\n }\n\n inner(collection: MultiSet<T>): MultiSet<U> {\n return collection.map(this.#f)\n }\n}\n\n/**\n * Applies a function to each element in the input stream\n * @param f - The function to apply to each element\n */\nexport function map<T, O>(f: (data: T) => O): PipedOperator<T, O> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<O> => {\n const output = new StreamBuilder<O>(\n stream.graph,\n new DifferenceStreamWriter<O>()\n )\n const operator = new MapOperator<T, O>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n output.writer,\n f\n )\n stream.graph.addOperator(operator)\n stream.graph.addStream(output.connectReader())\n return output\n }\n}\n"],"names":["LinearUnaryOperator","StreamBuilder","DifferenceStreamWriter"],"mappings":";;;;;;;;;;;;AASO,MAAM,oBAA0BA,MAAAA,oBAA0B;AAAA,EAG/D,YACE,IACA,QACA,QACA,GACA;AACA,UAAM,IAAI,QAAQ,MAAM;AAR1B;AASE,uBAAK,IAAK;AAAA,EACZ;AAAA,EAEA,MAAM,YAAsC;AAC1C,WAAO,WAAW,IAAI,mBAAK,GAAE;AAAA,EAC/B;AACF;AAfE;AAqBK,SAAS,IAAU,GAAwC;AAChE,SAAO,CAAC,WAAiD;AACvD,UAAM,SAAS,IAAIC,GAAAA;AAAAA,MACjB,OAAO;AAAA,MACP,IAAIC,MAAAA,uBAAA;AAAA,IAA0B;AAEhC,UAAM,WAAW,IAAI;AAAA,MACnB,OAAO,MAAM,kBAAA;AAAA,MACb,OAAO,cAAA;AAAA,MACP,OAAO;AAAA,MACP;AAAA,IAAA;AAEF,WAAO,MAAM,YAAY,QAAQ;AACjC,WAAO,MAAM,UAAU,OAAO,cAAA,CAAe;AAC7C,WAAO;AAAA,EACT;AACF;;;"}
@@ -0,0 +1,16 @@
1
+ import { DifferenceStreamWriter, LinearUnaryOperator, DifferenceStreamReader } from '../graph.js';
2
+ import { PipedOperator } from '../types.js';
3
+ import { MultiSet } from '../multiset.js';
4
+ /**
5
+ * Operator that applies a function to each element in the input stream
6
+ */
7
+ export declare class MapOperator<T, U> extends LinearUnaryOperator<T, U> {
8
+ #private;
9
+ constructor(id: number, inputA: DifferenceStreamReader<T>, output: DifferenceStreamWriter<U>, f: (data: T) => U);
10
+ inner(collection: MultiSet<T>): MultiSet<U>;
11
+ }
12
+ /**
13
+ * Applies a function to each element in the input stream
14
+ * @param f - The function to apply to each element
15
+ */
16
+ export declare function map<T, O>(f: (data: T) => O): PipedOperator<T, O>;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const graph = require("../graph.cjs");
4
+ const d2 = require("../d2.cjs");
5
+ class NegateOperator extends graph.LinearUnaryOperator {
6
+ inner(collection) {
7
+ return collection.negate();
8
+ }
9
+ }
10
+ function negate() {
11
+ return (stream) => {
12
+ const output = new d2.StreamBuilder(
13
+ stream.graph,
14
+ new graph.DifferenceStreamWriter()
15
+ );
16
+ const operator = new NegateOperator(
17
+ stream.graph.getNextOperatorId(),
18
+ stream.connectReader(),
19
+ output.writer
20
+ );
21
+ stream.graph.addOperator(operator);
22
+ stream.graph.addStream(output.connectReader());
23
+ return output;
24
+ };
25
+ }
26
+ exports.NegateOperator = NegateOperator;
27
+ exports.negate = negate;
28
+ //# sourceMappingURL=negate.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"negate.cjs","sources":["../../../src/operators/negate.ts"],"sourcesContent":["import { DifferenceStreamWriter, LinearUnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types.js\"\nimport type { MultiSet } from \"../multiset.js\"\n\n/**\n * Operator that negates the multiplicities in the input stream\n */\nexport class NegateOperator<T> extends LinearUnaryOperator<T, T> {\n inner(collection: MultiSet<T>): MultiSet<T> {\n return collection.negate()\n }\n}\n\n/**\n * Negates the multiplicities in the input stream\n */\nexport function negate<T>(): PipedOperator<T, T> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const output = new StreamBuilder<T>(\n stream.graph,\n new DifferenceStreamWriter<T>()\n )\n const operator = new NegateOperator<T>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n output.writer\n )\n stream.graph.addOperator(operator)\n stream.graph.addStream(output.connectReader())\n return output\n }\n}\n"],"names":["LinearUnaryOperator","StreamBuilder","DifferenceStreamWriter"],"mappings":";;;;AAQO,MAAM,uBAA0BA,MAAAA,oBAA0B;AAAA,EAC/D,MAAM,YAAsC;AAC1C,WAAO,WAAW,OAAA;AAAA,EACpB;AACF;AAKO,SAAS,SAAiC;AAC/C,SAAO,CAAC,WAAiD;AACvD,UAAM,SAAS,IAAIC,GAAAA;AAAAA,MACjB,OAAO;AAAA,MACP,IAAIC,MAAAA,uBAAA;AAAA,IAA0B;AAEhC,UAAM,WAAW,IAAI;AAAA,MACnB,OAAO,MAAM,kBAAA;AAAA,MACb,OAAO,cAAA;AAAA,MACP,OAAO;AAAA,IAAA;AAET,WAAO,MAAM,YAAY,QAAQ;AACjC,WAAO,MAAM,UAAU,OAAO,cAAA,CAAe;AAC7C,WAAO;AAAA,EACT;AACF;;;"}
@@ -0,0 +1,13 @@
1
+ import { LinearUnaryOperator } from '../graph.js';
2
+ import { PipedOperator } from '../types.js';
3
+ import { MultiSet } from '../multiset.js';
4
+ /**
5
+ * Operator that negates the multiplicities in the input stream
6
+ */
7
+ export declare class NegateOperator<T> extends LinearUnaryOperator<T, T> {
8
+ inner(collection: MultiSet<T>): MultiSet<T>;
9
+ }
10
+ /**
11
+ * Negates the multiplicities in the input stream
12
+ */
13
+ export declare function negate<T>(): PipedOperator<T, T>;
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const topK = require("./topK.cjs");
4
+ const topKWithFractionalIndex = require("./topKWithFractionalIndex.cjs");
5
+ const map = require("./map.cjs");
6
+ const join = require("./join.cjs");
7
+ const consolidate = require("./consolidate.cjs");
8
+ function orderBy(valueExtractor, options) {
9
+ const limit = (options == null ? void 0 : options.limit) ?? Infinity;
10
+ const offset = (options == null ? void 0 : options.offset) ?? 0;
11
+ const comparator = (options == null ? void 0 : options.comparator) ?? ((a, b) => {
12
+ if (a === b) return 0;
13
+ if (a < b) return -1;
14
+ return 1;
15
+ });
16
+ return (stream) => {
17
+ return stream.pipe(
18
+ map.map(
19
+ ([key, value]) => [
20
+ null,
21
+ [
22
+ key,
23
+ valueExtractor(
24
+ value
25
+ )
26
+ ]
27
+ ]
28
+ ),
29
+ topK.topK((a, b) => comparator(a[1], b[1]), { limit, offset }),
30
+ map.map(([_, [key]]) => [key, null]),
31
+ join.innerJoin(stream),
32
+ map.map(([key, value]) => {
33
+ return [key, value[1]];
34
+ }),
35
+ consolidate.consolidate()
36
+ );
37
+ };
38
+ }
39
+ function orderByWithIndex(valueExtractor, options) {
40
+ const limit = (options == null ? void 0 : options.limit) ?? Infinity;
41
+ const offset = (options == null ? void 0 : options.offset) ?? 0;
42
+ const comparator = (options == null ? void 0 : options.comparator) ?? ((a, b) => {
43
+ if (a === b) return 0;
44
+ if (a < b) return -1;
45
+ return 1;
46
+ });
47
+ return (stream) => {
48
+ return stream.pipe(
49
+ map.map(
50
+ ([key, value]) => [
51
+ null,
52
+ [
53
+ key,
54
+ valueExtractor(
55
+ value
56
+ )
57
+ ]
58
+ ]
59
+ ),
60
+ topK.topKWithIndex((a, b) => comparator(a[1], b[1]), { limit, offset }),
61
+ map.map(([_, [[key], index]]) => [key, index]),
62
+ join.innerJoin(stream),
63
+ map.map(([key, [index, value]]) => {
64
+ return [key, [value, index]];
65
+ }),
66
+ consolidate.consolidate()
67
+ );
68
+ };
69
+ }
70
+ function orderByWithFractionalIndexBase(topKFunction, valueExtractor, options) {
71
+ const limit = (options == null ? void 0 : options.limit) ?? Infinity;
72
+ const offset = (options == null ? void 0 : options.offset) ?? 0;
73
+ const comparator = (options == null ? void 0 : options.comparator) ?? ((a, b) => {
74
+ if (a === b) return 0;
75
+ if (a < b) return -1;
76
+ return 1;
77
+ });
78
+ return (stream) => {
79
+ return stream.pipe(
80
+ map.map(
81
+ ([key, value]) => [
82
+ null,
83
+ [
84
+ key,
85
+ valueExtractor(
86
+ value
87
+ )
88
+ ]
89
+ ]
90
+ ),
91
+ topKFunction((a, b) => comparator(a[1], b[1]), {
92
+ limit,
93
+ offset
94
+ }),
95
+ map.map(([_, [[key], index]]) => [key, index]),
96
+ join.innerJoin(stream),
97
+ map.map(([key, [index, value]]) => {
98
+ return [key, [value, index]];
99
+ }),
100
+ consolidate.consolidate()
101
+ );
102
+ };
103
+ }
104
+ function orderByWithFractionalIndex(valueExtractor, options) {
105
+ return orderByWithFractionalIndexBase(
106
+ topKWithFractionalIndex.topKWithFractionalIndex,
107
+ valueExtractor,
108
+ options
109
+ );
110
+ }
111
+ exports.orderBy = orderBy;
112
+ exports.orderByWithFractionalIndex = orderByWithFractionalIndex;
113
+ exports.orderByWithFractionalIndexBase = orderByWithFractionalIndexBase;
114
+ exports.orderByWithIndex = orderByWithIndex;
115
+ //# sourceMappingURL=orderBy.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orderBy.cjs","sources":["../../../src/operators/orderBy.ts"],"sourcesContent":["import { topK, topKWithIndex } from \"./topK.js\"\nimport { topKWithFractionalIndex } from \"./topKWithFractionalIndex.js\"\nimport { map } from \"./map.js\"\nimport { innerJoin } from \"./join.js\"\nimport { consolidate } from \"./consolidate.js\"\nimport type { KeyValue } from \"../types.js\"\nimport type { IStreamBuilder } from \"../types\"\n\nexport interface OrderByOptions<Ve> {\n comparator?: (a: Ve, b: Ve) => number\n limit?: number\n offset?: number\n}\n\n/**\n * Orders the elements and limits the number of results, with optional offset\n * This requires a keyed stream, and uses the `topK` operator to order all the elements.\n *\n * @param valueExtractor - A function that extracts the value to order by from the element\n * @param options - An optional object containing comparator, limit and offset properties\n * @returns A piped operator that orders the elements and limits the number of results\n */\nexport function orderBy<T extends KeyValue<unknown, unknown>, Ve = unknown>(\n valueExtractor: (\n value: T extends KeyValue<unknown, infer V> ? V : never\n ) => Ve,\n options?: OrderByOptions<Ve>\n) {\n const limit = options?.limit ?? Infinity\n const offset = options?.offset ?? 0\n const comparator =\n options?.comparator ??\n ((a, b) => {\n // Default to JS like ordering\n if (a === b) return 0\n if (a < b) return -1\n return 1\n })\n\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n type KeyType = T extends KeyValue<infer K, unknown> ? K : never\n\n return stream.pipe(\n map(\n ([key, value]) =>\n [\n null,\n [\n key,\n valueExtractor(\n value as T extends KeyValue<unknown, infer V> ? V : never\n ),\n ],\n ] as KeyValue<null, [KeyType, Ve]>\n ),\n topK((a, b) => comparator(a[1], b[1]), { limit, offset }),\n map(([_, [key]]) => [key, null] as KeyValue<KeyType, null>),\n innerJoin(stream),\n map(([key, value]) => {\n return [key, value[1]] as T\n }),\n consolidate()\n )\n }\n}\n\n/**\n * Orders the elements and limits the number of results, with optional offset and\n * annotates the value with the index.\n * This requires a keyed stream, and uses the `topKWithIndex` operator to order all the elements.\n *\n * @param valueExtractor - A function that extracts the value to order by from the element\n * @param options - An optional object containing comparator, limit and offset properties\n * @returns A piped operator that orders the elements and limits the number of results\n */\nexport function orderByWithIndex<\n T extends KeyValue<unknown, unknown>,\n Ve = unknown,\n>(\n valueExtractor: (\n value: T extends KeyValue<unknown, infer V> ? V : never\n ) => Ve,\n options?: OrderByOptions<Ve>\n) {\n const limit = options?.limit ?? Infinity\n const offset = options?.offset ?? 0\n const comparator =\n options?.comparator ??\n ((a, b) => {\n // Default to JS like ordering\n if (a === b) return 0\n if (a < b) return -1\n return 1\n })\n\n return (\n stream: IStreamBuilder<T>\n ): IStreamBuilder<\n KeyValue<\n T extends KeyValue<infer K, unknown> ? K : never,\n [T extends KeyValue<unknown, infer V> ? V : never, number]\n >\n > => {\n type KeyType = T extends KeyValue<infer K, unknown> ? K : never\n type ValueType = T extends KeyValue<unknown, infer V> ? V : never\n\n return stream.pipe(\n map(\n ([key, value]) =>\n [\n null,\n [\n key,\n valueExtractor(\n value as T extends KeyValue<unknown, infer V> ? V : never\n ),\n ],\n ] as KeyValue<null, [KeyType, Ve]>\n ),\n topKWithIndex((a, b) => comparator(a[1], b[1]), { limit, offset }),\n map(([_, [[key], index]]) => [key, index] as KeyValue<KeyType, number>),\n innerJoin(stream),\n map(([key, [index, value]]) => {\n return [key, [value, index]] as KeyValue<KeyType, [ValueType, number]>\n }),\n consolidate()\n )\n }\n}\n\nexport function orderByWithFractionalIndexBase<\n T extends KeyValue<unknown, unknown>,\n Ve = unknown,\n>(\n topKFunction: typeof topKWithFractionalIndex,\n valueExtractor: (\n value: T extends KeyValue<unknown, infer V> ? V : never\n ) => Ve,\n options?: OrderByOptions<Ve>\n) {\n const limit = options?.limit ?? Infinity\n const offset = options?.offset ?? 0\n const comparator =\n options?.comparator ??\n ((a, b) => {\n // Default to JS like ordering\n if (a === b) return 0\n if (a < b) return -1\n return 1\n })\n\n return (\n stream: IStreamBuilder<T>\n ): IStreamBuilder<\n KeyValue<\n T extends KeyValue<infer K, unknown> ? K : never,\n [T extends KeyValue<unknown, infer V> ? V : never, string]\n >\n > => {\n type KeyType = T extends KeyValue<infer K, unknown> ? K : never\n type ValueType = T extends KeyValue<unknown, infer V> ? V : never\n\n return stream.pipe(\n map(\n ([key, value]) =>\n [\n null,\n [\n key,\n valueExtractor(\n value as T extends KeyValue<unknown, infer V> ? V : never\n ),\n ],\n ] as KeyValue<null, [KeyType, Ve]>\n ),\n topKFunction((a, b) => comparator(a[1], b[1]), {\n limit,\n offset,\n }),\n map(([_, [[key], index]]) => [key, index] as KeyValue<KeyType, string>),\n innerJoin(stream),\n map(([key, [index, value]]) => {\n return [key, [value, index]] as KeyValue<KeyType, [ValueType, string]>\n }),\n consolidate()\n )\n }\n}\n\n/**\n * Orders the elements and limits the number of results, with optional offset and\n * annotates the value with a fractional index.\n * This requires a keyed stream, and uses the `topKWithFractionalIndex` operator to order all the elements.\n *\n * @param valueExtractor - A function that extracts the value to order by from the element\n * @param options - An optional object containing comparator, limit and offset properties\n * @returns A piped operator that orders the elements and limits the number of results\n */\nexport function orderByWithFractionalIndex<\n T extends KeyValue<unknown, unknown>,\n Ve = unknown,\n>(\n valueExtractor: (\n value: T extends KeyValue<unknown, infer V> ? V : never\n ) => Ve,\n options?: OrderByOptions<Ve>\n) {\n return orderByWithFractionalIndexBase(\n topKWithFractionalIndex,\n valueExtractor,\n options\n )\n}\n"],"names":["map","topK","innerJoin","consolidate","topKWithIndex","topKWithFractionalIndex"],"mappings":";;;;;;;AAsBO,SAAS,QACd,gBAGA,SACA;AACA,QAAM,SAAQ,mCAAS,UAAS;AAChC,QAAM,UAAS,mCAAS,WAAU;AAClC,QAAM,cACJ,mCAAS,gBACR,CAAC,GAAG,MAAM;AAET,QAAI,MAAM,EAAG,QAAO;AACpB,QAAI,IAAI,EAAG,QAAO;AAClB,WAAO;AAAA,EACT;AAEF,SAAO,CAAC,WAAiD;AAGvD,WAAO,OAAO;AAAA,MACZA,IAAAA;AAAAA,QACE,CAAC,CAAC,KAAK,KAAK,MACV;AAAA,UACE;AAAA,UACA;AAAA,YACE;AAAA,YACA;AAAA,cACE;AAAA,YAAA;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,MAEJC,KAAAA,KAAK,CAAC,GAAG,MAAM,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,OAAO,QAAQ;AAAA,MACxDD,QAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,CAA4B;AAAA,MAC1DE,KAAAA,UAAU,MAAM;AAAA,MAChBF,IAAAA,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AACpB,eAAO,CAAC,KAAK,MAAM,CAAC,CAAC;AAAA,MACvB,CAAC;AAAA,MACDG,YAAAA,YAAA;AAAA,IAAY;AAAA,EAEhB;AACF;AAWO,SAAS,iBAId,gBAGA,SACA;AACA,QAAM,SAAQ,mCAAS,UAAS;AAChC,QAAM,UAAS,mCAAS,WAAU;AAClC,QAAM,cACJ,mCAAS,gBACR,CAAC,GAAG,MAAM;AAET,QAAI,MAAM,EAAG,QAAO;AACpB,QAAI,IAAI,EAAG,QAAO;AAClB,WAAO;AAAA,EACT;AAEF,SAAO,CACL,WAMG;AAIH,WAAO,OAAO;AAAA,MACZH,IAAAA;AAAAA,QACE,CAAC,CAAC,KAAK,KAAK,MACV;AAAA,UACE;AAAA,UACA;AAAA,YACE;AAAA,YACA;AAAA,cACE;AAAA,YAAA;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,MAEJI,KAAAA,cAAc,CAAC,GAAG,MAAM,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,OAAO,QAAQ;AAAA,MACjEJ,IAAAA,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,KAAK,CAA8B;AAAA,MACtEE,KAAAA,UAAU,MAAM;AAAA,MAChBF,IAAAA,IAAI,CAAC,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC,MAAM;AAC7B,eAAO,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC;AAAA,MAC7B,CAAC;AAAA,MACDG,YAAAA,YAAA;AAAA,IAAY;AAAA,EAEhB;AACF;AAEO,SAAS,+BAId,cACA,gBAGA,SACA;AACA,QAAM,SAAQ,mCAAS,UAAS;AAChC,QAAM,UAAS,mCAAS,WAAU;AAClC,QAAM,cACJ,mCAAS,gBACR,CAAC,GAAG,MAAM;AAET,QAAI,MAAM,EAAG,QAAO;AACpB,QAAI,IAAI,EAAG,QAAO;AAClB,WAAO;AAAA,EACT;AAEF,SAAO,CACL,WAMG;AAIH,WAAO,OAAO;AAAA,MACZH,IAAAA;AAAAA,QACE,CAAC,CAAC,KAAK,KAAK,MACV;AAAA,UACE;AAAA,UACA;AAAA,YACE;AAAA,YACA;AAAA,cACE;AAAA,YAAA;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,MAEJ,aAAa,CAAC,GAAG,MAAM,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG;AAAA,QAC7C;AAAA,QACA;AAAA,MAAA,CACD;AAAA,MACDA,IAAAA,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,KAAK,CAA8B;AAAA,MACtEE,KAAAA,UAAU,MAAM;AAAA,MAChBF,IAAAA,IAAI,CAAC,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC,MAAM;AAC7B,eAAO,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC;AAAA,MAC7B,CAAC;AAAA,MACDG,YAAAA,YAAA;AAAA,IAAY;AAAA,EAEhB;AACF;AAWO,SAAS,2BAId,gBAGA,SACA;AACA,SAAO;AAAA,IACLE,wBAAAA;AAAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;;;;;"}
@@ -0,0 +1,38 @@
1
+ import { topKWithFractionalIndex } from './topKWithFractionalIndex.js';
2
+ import { KeyValue } from '../types.js';
3
+ import { IStreamBuilder } from '../types.cjs';
4
+ export interface OrderByOptions<Ve> {
5
+ comparator?: (a: Ve, b: Ve) => number;
6
+ limit?: number;
7
+ offset?: number;
8
+ }
9
+ /**
10
+ * Orders the elements and limits the number of results, with optional offset
11
+ * This requires a keyed stream, and uses the `topK` operator to order all the elements.
12
+ *
13
+ * @param valueExtractor - A function that extracts the value to order by from the element
14
+ * @param options - An optional object containing comparator, limit and offset properties
15
+ * @returns A piped operator that orders the elements and limits the number of results
16
+ */
17
+ export declare function orderBy<T extends KeyValue<unknown, unknown>, Ve = unknown>(valueExtractor: (value: T extends KeyValue<unknown, infer V> ? V : never) => Ve, options?: OrderByOptions<Ve>): (stream: IStreamBuilder<T>) => IStreamBuilder<T>;
18
+ /**
19
+ * Orders the elements and limits the number of results, with optional offset and
20
+ * annotates the value with the index.
21
+ * This requires a keyed stream, and uses the `topKWithIndex` operator to order all the elements.
22
+ *
23
+ * @param valueExtractor - A function that extracts the value to order by from the element
24
+ * @param options - An optional object containing comparator, limit and offset properties
25
+ * @returns A piped operator that orders the elements and limits the number of results
26
+ */
27
+ export declare function orderByWithIndex<T extends KeyValue<unknown, unknown>, Ve = unknown>(valueExtractor: (value: T extends KeyValue<unknown, infer V> ? V : never) => Ve, options?: OrderByOptions<Ve>): (stream: IStreamBuilder<T>) => IStreamBuilder<KeyValue<T extends KeyValue<infer K, unknown> ? K : never, [T extends KeyValue<unknown, infer V> ? V : never, number]>>;
28
+ export declare function orderByWithFractionalIndexBase<T extends KeyValue<unknown, unknown>, Ve = unknown>(topKFunction: typeof topKWithFractionalIndex, valueExtractor: (value: T extends KeyValue<unknown, infer V> ? V : never) => Ve, options?: OrderByOptions<Ve>): (stream: IStreamBuilder<T>) => IStreamBuilder<KeyValue<T extends KeyValue<infer K, unknown> ? K : never, [T extends KeyValue<unknown, infer V> ? V : never, string]>>;
29
+ /**
30
+ * Orders the elements and limits the number of results, with optional offset and
31
+ * annotates the value with a fractional index.
32
+ * This requires a keyed stream, and uses the `topKWithFractionalIndex` operator to order all the elements.
33
+ *
34
+ * @param valueExtractor - A function that extracts the value to order by from the element
35
+ * @param options - An optional object containing comparator, limit and offset properties
36
+ * @returns A piped operator that orders the elements and limits the number of results
37
+ */
38
+ export declare function orderByWithFractionalIndex<T extends KeyValue<unknown, unknown>, Ve = unknown>(valueExtractor: (value: T extends KeyValue<unknown, infer V> ? V : never) => Ve, options?: OrderByOptions<Ve>): (stream: IStreamBuilder<T>) => IStreamBuilder<KeyValue<T extends KeyValue<infer K, unknown> ? K : never, [T extends KeyValue<unknown, infer V> ? V : never, string]>>;
@@ -0,0 +1,3 @@
1
+ import { KeyValue } from '../types.js';
2
+ import { OrderByOptions } from './orderBy.js';
3
+ export declare function orderByWithFractionalIndexBTree<T extends KeyValue<unknown, unknown>, Ve = unknown>(valueExtractor: (value: T extends KeyValue<unknown, infer V> ? V : never) => Ve, options?: OrderByOptions<Ve>): (stream: import('../types.js').IStreamBuilder<T>) => import('../types.js').IStreamBuilder<KeyValue<T extends KeyValue<infer K, unknown> ? K : never, [T extends KeyValue<unknown, infer V> ? V : never, string]>>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __typeError = (msg) => {
3
+ throw TypeError(msg);
4
+ };
5
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
6
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
7
+ 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);
8
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
9
+ var _fn;
10
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
11
+ const graph = require("../graph.cjs");
12
+ const d2 = require("../d2.cjs");
13
+ class OutputOperator extends graph.UnaryOperator {
14
+ constructor(id, inputA, outputWriter, fn) {
15
+ super(id, inputA, outputWriter);
16
+ __privateAdd(this, _fn);
17
+ __privateSet(this, _fn, fn);
18
+ }
19
+ run() {
20
+ for (const message of this.inputMessages()) {
21
+ __privateGet(this, _fn).call(this, message);
22
+ this.output.sendData(message);
23
+ }
24
+ }
25
+ }
26
+ _fn = new WeakMap();
27
+ function output(fn) {
28
+ return (stream) => {
29
+ const outputStream = new d2.StreamBuilder(
30
+ stream.graph,
31
+ new graph.DifferenceStreamWriter()
32
+ );
33
+ const operator = new OutputOperator(
34
+ stream.graph.getNextOperatorId(),
35
+ stream.connectReader(),
36
+ outputStream.writer,
37
+ fn
38
+ );
39
+ stream.graph.addOperator(operator);
40
+ stream.graph.addStream(outputStream.connectReader());
41
+ return outputStream;
42
+ };
43
+ }
44
+ exports.OutputOperator = OutputOperator;
45
+ exports.output = output;
46
+ //# sourceMappingURL=output.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.cjs","sources":["../../../src/operators/output.ts"],"sourcesContent":["import { DifferenceStreamWriter, UnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\nimport type { MultiSet } from \"../multiset.js\"\n\n/**\n * Operator that outputs the messages in the stream\n */\nexport class OutputOperator<T> extends UnaryOperator<T> {\n #fn: (data: MultiSet<T>) => void\n\n constructor(\n id: number,\n inputA: DifferenceStreamReader<T>,\n outputWriter: DifferenceStreamWriter<T>,\n fn: (data: MultiSet<T>) => void\n ) {\n super(id, inputA, outputWriter)\n this.#fn = fn\n }\n\n run(): void {\n for (const message of this.inputMessages()) {\n this.#fn(message)\n this.output.sendData(message)\n }\n }\n}\n\n/**\n * Outputs the messages in the stream\n * @param fn - The function to call with each message\n */\nexport function output<T>(\n fn: (data: MultiSet<T>) => void\n): PipedOperator<T, T> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const outputStream = new StreamBuilder<T>(\n stream.graph,\n new DifferenceStreamWriter<T>()\n )\n const operator = new OutputOperator<T>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n outputStream.writer,\n fn\n )\n stream.graph.addOperator(operator)\n stream.graph.addStream(outputStream.connectReader())\n return outputStream\n }\n}\n"],"names":["UnaryOperator","StreamBuilder","DifferenceStreamWriter"],"mappings":";;;;;;;;;;;;AASO,MAAM,uBAA0BA,MAAAA,cAAiB;AAAA,EAGtD,YACE,IACA,QACA,cACA,IACA;AACA,UAAM,IAAI,QAAQ,YAAY;AARhC;AASE,uBAAK,KAAM;AAAA,EACb;AAAA,EAEA,MAAY;AACV,eAAW,WAAW,KAAK,iBAAiB;AAC1C,yBAAK,KAAL,WAAS;AACT,WAAK,OAAO,SAAS,OAAO;AAAA,IAC9B;AAAA,EACF;AACF;AAlBE;AAwBK,SAAS,OACd,IACqB;AACrB,SAAO,CAAC,WAAiD;AACvD,UAAM,eAAe,IAAIC,GAAAA;AAAAA,MACvB,OAAO;AAAA,MACP,IAAIC,MAAAA,uBAAA;AAAA,IAA0B;AAEhC,UAAM,WAAW,IAAI;AAAA,MACnB,OAAO,MAAM,kBAAA;AAAA,MACb,OAAO,cAAA;AAAA,MACP,aAAa;AAAA,MACb;AAAA,IAAA;AAEF,WAAO,MAAM,YAAY,QAAQ;AACjC,WAAO,MAAM,UAAU,aAAa,cAAA,CAAe;AACnD,WAAO;AAAA,EACT;AACF;;;"}
@@ -0,0 +1,16 @@
1
+ import { DifferenceStreamWriter, UnaryOperator, DifferenceStreamReader } from '../graph.js';
2
+ import { PipedOperator } from '../types.js';
3
+ import { MultiSet } from '../multiset.js';
4
+ /**
5
+ * Operator that outputs the messages in the stream
6
+ */
7
+ export declare class OutputOperator<T> extends UnaryOperator<T> {
8
+ #private;
9
+ constructor(id: number, inputA: DifferenceStreamReader<T>, outputWriter: DifferenceStreamWriter<T>, fn: (data: MultiSet<T>) => void);
10
+ run(): void;
11
+ }
12
+ /**
13
+ * Outputs the messages in the stream
14
+ * @param fn - The function to call with each message
15
+ */
16
+ export declare function output<T>(fn: (data: MultiSet<T>) => void): PipedOperator<T, T>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function pipe(...operators) {
4
+ return (stream) => {
5
+ return stream.pipe(...operators);
6
+ };
7
+ }
8
+ exports.pipe = pipe;
9
+ //# sourceMappingURL=pipe.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipe.cjs","sources":["../../../src/operators/pipe.ts"],"sourcesContent":["import type { IStreamBuilder, PipedOperator } from \"../types.js\"\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 surely that's enough for anyone...\n// A user can always split the pipe into multiple pipes to get around this.\nexport function pipe<T, O>(o1: PipedOperator<T, O>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, T2, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, O>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, T2, T3, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, O>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, T2, T3, T4, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, O>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n// prettier-ignore\nexport function pipe<T, 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>): PipedOperator<T, O>\n\n/**\n * Creates a new stream by piping the input stream through a series of operators\n */\nexport function pipe<T>(...operators: Array<PipedOperator<any, any>>) {\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n return stream.pipe(...operators)\n }\n}\n"],"names":[],"mappings":";;AAkDO,SAAS,QAAW,WAA2C;AACpE,SAAO,CAAC,WAAiD;AACvD,WAAO,OAAO,KAAK,GAAG,SAAS;AAAA,EACjC;AACF;;"}
@@ -0,0 +1,21 @@
1
+ import { PipedOperator } from '../types.js';
2
+ export declare function pipe<T, O>(o1: PipedOperator<T, O>): PipedOperator<T, O>;
3
+ export declare function pipe<T, T2, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, O>): PipedOperator<T, O>;
4
+ export declare function pipe<T, T2, T3, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, O>): PipedOperator<T, O>;
5
+ export declare function pipe<T, T2, T3, T4, O>(o1: PipedOperator<T, T2>, o2: PipedOperator<T2, T3>, o3: PipedOperator<T3, T4>, o4: PipedOperator<T4, O>): PipedOperator<T, O>;
6
+ export declare function pipe<T, 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>): PipedOperator<T, O>;
7
+ export declare function pipe<T, 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>): PipedOperator<T, O>;
8
+ export declare function pipe<T, 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>): PipedOperator<T, O>;
9
+ export declare function pipe<T, 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>): PipedOperator<T, O>;
10
+ export declare function pipe<T, 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>): PipedOperator<T, O>;
11
+ export declare function pipe<T, 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>): PipedOperator<T, O>;
12
+ export declare function pipe<T, 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>): PipedOperator<T, O>;
13
+ export declare function pipe<T, 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>): PipedOperator<T, O>;
14
+ export declare function pipe<T, 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>): PipedOperator<T, O>;
15
+ export declare function pipe<T, 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>): PipedOperator<T, O>;
16
+ export declare function pipe<T, 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>): PipedOperator<T, O>;
17
+ export declare function pipe<T, 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>): PipedOperator<T, O>;
18
+ export declare function pipe<T, 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>): PipedOperator<T, O>;
19
+ export declare function pipe<T, 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>): PipedOperator<T, O>;
20
+ export declare function pipe<T, 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>): PipedOperator<T, O>;
21
+ export declare function pipe<T, 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>): PipedOperator<T, O>;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __typeError = (msg) => {
3
+ throw TypeError(msg);
4
+ };
5
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
6
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
7
+ 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);
8
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
9
+ var _index, _indexOut, _f;
10
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
11
+ const graph = require("../graph.cjs");
12
+ const d2 = require("../d2.cjs");
13
+ const multiset = require("../multiset.cjs");
14
+ const indexes = require("../indexes.cjs");
15
+ class ReduceOperator extends graph.UnaryOperator {
16
+ constructor(id, inputA, output, f) {
17
+ super(id, inputA, output);
18
+ __privateAdd(this, _index, new indexes.Index());
19
+ __privateAdd(this, _indexOut, new indexes.Index());
20
+ __privateAdd(this, _f);
21
+ __privateSet(this, _f, f);
22
+ }
23
+ run() {
24
+ const keysTodo = /* @__PURE__ */ new Set();
25
+ for (const message of this.inputMessages()) {
26
+ for (const [item, multiplicity] of message.getInner()) {
27
+ const [key, value] = item;
28
+ __privateGet(this, _index).addValue(key, [value, multiplicity]);
29
+ keysTodo.add(key);
30
+ }
31
+ }
32
+ const result = [];
33
+ for (const key of keysTodo) {
34
+ const curr = __privateGet(this, _index).get(key);
35
+ const currOut = __privateGet(this, _indexOut).get(key);
36
+ const out = __privateGet(this, _f).call(this, curr);
37
+ const newOutputMap = /* @__PURE__ */ new Map();
38
+ const oldOutputMap = /* @__PURE__ */ new Map();
39
+ for (const [value, multiplicity] of out) {
40
+ const existing = newOutputMap.get(value) ?? 0;
41
+ newOutputMap.set(value, existing + multiplicity);
42
+ }
43
+ for (const [value, multiplicity] of currOut) {
44
+ const existing = oldOutputMap.get(value) ?? 0;
45
+ oldOutputMap.set(value, existing + multiplicity);
46
+ }
47
+ for (const [value, multiplicity] of oldOutputMap) {
48
+ if (!newOutputMap.has(value)) {
49
+ result.push([[key, value], -multiplicity]);
50
+ __privateGet(this, _indexOut).addValue(key, [value, -multiplicity]);
51
+ }
52
+ }
53
+ for (const [value, multiplicity] of newOutputMap) {
54
+ if (!oldOutputMap.has(value)) {
55
+ if (multiplicity !== 0) {
56
+ result.push([[key, value], multiplicity]);
57
+ __privateGet(this, _indexOut).addValue(key, [value, multiplicity]);
58
+ }
59
+ }
60
+ }
61
+ for (const [value, newMultiplicity] of newOutputMap) {
62
+ const oldMultiplicity = oldOutputMap.get(value);
63
+ if (oldMultiplicity !== void 0) {
64
+ const delta = newMultiplicity - oldMultiplicity;
65
+ if (delta !== 0) {
66
+ result.push([[key, value], delta]);
67
+ __privateGet(this, _indexOut).addValue(key, [value, delta]);
68
+ }
69
+ }
70
+ }
71
+ }
72
+ if (result.length > 0) {
73
+ this.output.sendData(new multiset.MultiSet(result));
74
+ }
75
+ }
76
+ }
77
+ _index = new WeakMap();
78
+ _indexOut = new WeakMap();
79
+ _f = new WeakMap();
80
+ function reduce(f) {
81
+ return (stream) => {
82
+ const output = new d2.StreamBuilder(
83
+ stream.graph,
84
+ new graph.DifferenceStreamWriter()
85
+ );
86
+ const operator = new ReduceOperator(
87
+ stream.graph.getNextOperatorId(),
88
+ stream.connectReader(),
89
+ output.writer,
90
+ f
91
+ );
92
+ stream.graph.addOperator(operator);
93
+ stream.graph.addStream(output.connectReader());
94
+ return output;
95
+ };
96
+ }
97
+ exports.ReduceOperator = ReduceOperator;
98
+ exports.reduce = reduce;
99
+ //# sourceMappingURL=reduce.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reduce.cjs","sources":["../../../src/operators/reduce.ts"],"sourcesContent":["import { DifferenceStreamWriter, UnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport { MultiSet } from \"../multiset.js\"\nimport { Index } from \"../indexes.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\nimport type { IStreamBuilder, KeyValue } from \"../types.js\"\n\n/**\n * Base operator for reduction operations (version-free)\n */\nexport class ReduceOperator<K, V1, V2> extends UnaryOperator<[K, V1], [K, V2]> {\n #index = new Index<K, V1>()\n #indexOut = new Index<K, V2>()\n #f: (values: Array<[V1, number]>) => Array<[V2, number]>\n\n constructor(\n id: number,\n inputA: DifferenceStreamReader<[K, V1]>,\n output: DifferenceStreamWriter<[K, V2]>,\n f: (values: Array<[V1, number]>) => Array<[V2, number]>\n ) {\n super(id, inputA, output)\n this.#f = f\n }\n\n run(): void {\n // Collect all input messages and update the index\n const keysTodo = new Set<K>()\n for (const message of this.inputMessages()) {\n for (const [item, multiplicity] of message.getInner()) {\n const [key, value] = item\n this.#index.addValue(key, [value, multiplicity])\n keysTodo.add(key)\n }\n }\n\n // For each key, compute the reduction and delta\n const result: Array<[[K, V2], number]> = []\n for (const key of keysTodo) {\n const curr = this.#index.get(key)\n const currOut = this.#indexOut.get(key)\n const out = this.#f(curr)\n\n // Create maps for current and previous outputs using values directly as keys\n const newOutputMap = new Map<V2, number>()\n const oldOutputMap = new Map<V2, number>()\n\n // Process new output\n for (const [value, multiplicity] of out) {\n const existing = newOutputMap.get(value) ?? 0\n newOutputMap.set(value, existing + multiplicity)\n }\n\n // Process previous output\n for (const [value, multiplicity] of currOut) {\n const existing = oldOutputMap.get(value) ?? 0\n oldOutputMap.set(value, existing + multiplicity)\n }\n\n // First, emit removals for old values that are no longer present\n for (const [value, multiplicity] of oldOutputMap) {\n if (!newOutputMap.has(value)) {\n // Remove the old value entirely\n result.push([[key, value], -multiplicity])\n this.#indexOut.addValue(key, [value, -multiplicity])\n }\n }\n\n // Then, emit additions for new values that are not present in old\n for (const [value, multiplicity] of newOutputMap) {\n if (!oldOutputMap.has(value)) {\n // Add the new value only if it has non-zero multiplicity\n if (multiplicity !== 0) {\n result.push([[key, value], multiplicity])\n this.#indexOut.addValue(key, [value, multiplicity])\n }\n }\n }\n\n // Finally, emit multiplicity changes for values that were present and are still present\n for (const [value, newMultiplicity] of newOutputMap) {\n const oldMultiplicity = oldOutputMap.get(value)\n if (oldMultiplicity !== undefined) {\n const delta = newMultiplicity - oldMultiplicity\n // Only emit actual changes, i.e. non-zero deltas\n if (delta !== 0) {\n result.push([[key, value], delta])\n this.#indexOut.addValue(key, [value, delta])\n }\n }\n }\n }\n\n if (result.length > 0) {\n this.output.sendData(new MultiSet(result))\n }\n }\n}\n\n/**\n * Reduces the elements in the stream by key (version-free)\n */\nexport function reduce<\n KType extends T extends KeyValue<infer K, infer _V> ? K : never,\n V1Type extends T extends KeyValue<KType, infer V> ? V : never,\n R,\n T,\n>(f: (values: Array<[V1Type, number]>) => Array<[R, number]>) {\n return (stream: IStreamBuilder<T>): IStreamBuilder<KeyValue<KType, R>> => {\n const output = new StreamBuilder<KeyValue<KType, R>>(\n stream.graph,\n new DifferenceStreamWriter<KeyValue<KType, R>>()\n )\n const operator = new ReduceOperator<KType, V1Type, R>(\n stream.graph.getNextOperatorId(),\n stream.connectReader() as DifferenceStreamReader<KeyValue<KType, V1Type>>,\n output.writer,\n f\n )\n stream.graph.addOperator(operator)\n stream.graph.addStream(output.connectReader())\n return output\n }\n}\n"],"names":["UnaryOperator","Index","MultiSet","StreamBuilder","DifferenceStreamWriter"],"mappings":";;;;;;;;;;;;;;AAUO,MAAM,uBAAkCA,MAAAA,cAAgC;AAAA,EAK7E,YACE,IACA,QACA,QACA,GACA;AACA,UAAM,IAAI,QAAQ,MAAM;AAV1B,+BAAS,IAAIC,QAAAA,MAAA;AACb,kCAAY,IAAIA,QAAAA,MAAA;AAChB;AASE,uBAAK,IAAK;AAAA,EACZ;AAAA,EAEA,MAAY;AAEV,UAAM,+BAAe,IAAA;AACrB,eAAW,WAAW,KAAK,iBAAiB;AAC1C,iBAAW,CAAC,MAAM,YAAY,KAAK,QAAQ,YAAY;AACrD,cAAM,CAAC,KAAK,KAAK,IAAI;AACrB,2BAAK,QAAO,SAAS,KAAK,CAAC,OAAO,YAAY,CAAC;AAC/C,iBAAS,IAAI,GAAG;AAAA,MAClB;AAAA,IACF;AAGA,UAAM,SAAmC,CAAA;AACzC,eAAW,OAAO,UAAU;AAC1B,YAAM,OAAO,mBAAK,QAAO,IAAI,GAAG;AAChC,YAAM,UAAU,mBAAK,WAAU,IAAI,GAAG;AACtC,YAAM,MAAM,mBAAK,IAAL,WAAQ;AAGpB,YAAM,mCAAmB,IAAA;AACzB,YAAM,mCAAmB,IAAA;AAGzB,iBAAW,CAAC,OAAO,YAAY,KAAK,KAAK;AACvC,cAAM,WAAW,aAAa,IAAI,KAAK,KAAK;AAC5C,qBAAa,IAAI,OAAO,WAAW,YAAY;AAAA,MACjD;AAGA,iBAAW,CAAC,OAAO,YAAY,KAAK,SAAS;AAC3C,cAAM,WAAW,aAAa,IAAI,KAAK,KAAK;AAC5C,qBAAa,IAAI,OAAO,WAAW,YAAY;AAAA,MACjD;AAGA,iBAAW,CAAC,OAAO,YAAY,KAAK,cAAc;AAChD,YAAI,CAAC,aAAa,IAAI,KAAK,GAAG;AAE5B,iBAAO,KAAK,CAAC,CAAC,KAAK,KAAK,GAAG,CAAC,YAAY,CAAC;AACzC,6BAAK,WAAU,SAAS,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC;AAAA,QACrD;AAAA,MACF;AAGA,iBAAW,CAAC,OAAO,YAAY,KAAK,cAAc;AAChD,YAAI,CAAC,aAAa,IAAI,KAAK,GAAG;AAE5B,cAAI,iBAAiB,GAAG;AACtB,mBAAO,KAAK,CAAC,CAAC,KAAK,KAAK,GAAG,YAAY,CAAC;AACxC,+BAAK,WAAU,SAAS,KAAK,CAAC,OAAO,YAAY,CAAC;AAAA,UACpD;AAAA,QACF;AAAA,MACF;AAGA,iBAAW,CAAC,OAAO,eAAe,KAAK,cAAc;AACnD,cAAM,kBAAkB,aAAa,IAAI,KAAK;AAC9C,YAAI,oBAAoB,QAAW;AACjC,gBAAM,QAAQ,kBAAkB;AAEhC,cAAI,UAAU,GAAG;AACf,mBAAO,KAAK,CAAC,CAAC,KAAK,KAAK,GAAG,KAAK,CAAC;AACjC,+BAAK,WAAU,SAAS,KAAK,CAAC,OAAO,KAAK,CAAC;AAAA,UAC7C;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,QAAI,OAAO,SAAS,GAAG;AACrB,WAAK,OAAO,SAAS,IAAIC,SAAAA,SAAS,MAAM,CAAC;AAAA,IAC3C;AAAA,EACF;AACF;AAtFE;AACA;AACA;AAyFK,SAAS,OAKd,GAA4D;AAC5D,SAAO,CAAC,WAAkE;AACxE,UAAM,SAAS,IAAIC,GAAAA;AAAAA,MACjB,OAAO;AAAA,MACP,IAAIC,MAAAA,uBAAA;AAAA,IAA2C;AAEjD,UAAM,WAAW,IAAI;AAAA,MACnB,OAAO,MAAM,kBAAA;AAAA,MACb,OAAO,cAAA;AAAA,MACP,OAAO;AAAA,MACP;AAAA,IAAA;AAEF,WAAO,MAAM,YAAY,QAAQ;AACjC,WAAO,MAAM,UAAU,OAAO,cAAA,CAAe;AAC7C,WAAO;AAAA,EACT;AACF;;;"}
@@ -0,0 +1,14 @@
1
+ import { DifferenceStreamWriter, UnaryOperator, DifferenceStreamReader } from '../graph.js';
2
+ import { IStreamBuilder, KeyValue } from '../types.js';
3
+ /**
4
+ * Base operator for reduction operations (version-free)
5
+ */
6
+ export declare class ReduceOperator<K, V1, V2> extends UnaryOperator<[K, V1], [K, V2]> {
7
+ #private;
8
+ constructor(id: number, inputA: DifferenceStreamReader<[K, V1]>, output: DifferenceStreamWriter<[K, V2]>, f: (values: Array<[V1, number]>) => Array<[V2, number]>);
9
+ run(): void;
10
+ }
11
+ /**
12
+ * Reduces the elements in the stream by key (version-free)
13
+ */
14
+ export declare function reduce<KType extends T extends KeyValue<infer K, infer _V> ? K : never, V1Type extends T extends KeyValue<KType, infer V> ? V : never, R, T>(f: (values: Array<[V1Type, number]>) => Array<[R, number]>): (stream: IStreamBuilder<T>) => IStreamBuilder<KeyValue<KType, R>>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const multiset = require("../multiset.cjs");
4
+ const reduce = require("./reduce.cjs");
5
+ function topK(comparator, options) {
6
+ const limit = (options == null ? void 0 : options.limit) ?? Infinity;
7
+ const offset = (options == null ? void 0 : options.offset) ?? 0;
8
+ return (stream) => {
9
+ const reduced = stream.pipe(
10
+ reduce.reduce((values) => {
11
+ const consolidated = new multiset.MultiSet(values).consolidate();
12
+ const sortedValues = consolidated.getInner().sort((a, b) => comparator(a[0], b[0]));
13
+ return sortedValues.slice(offset, offset + limit);
14
+ })
15
+ );
16
+ return reduced;
17
+ };
18
+ }
19
+ function topKWithIndex(comparator, options) {
20
+ const limit = (options == null ? void 0 : options.limit) ?? Infinity;
21
+ const offset = (options == null ? void 0 : options.offset) ?? 0;
22
+ return (stream) => {
23
+ const reduced = stream.pipe(
24
+ reduce.reduce((values) => {
25
+ const consolidated = new multiset.MultiSet(values).consolidate();
26
+ let i = offset;
27
+ const sortedValues = consolidated.getInner().sort((a, b) => comparator(a[0], b[0])).slice(offset, offset + limit).map(([value, multiplicity]) => [
28
+ [value, i++],
29
+ multiplicity
30
+ ]);
31
+ return sortedValues;
32
+ })
33
+ );
34
+ return reduced;
35
+ };
36
+ }
37
+ exports.topK = topK;
38
+ exports.topKWithIndex = topKWithIndex;
39
+ //# sourceMappingURL=topK.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"topK.cjs","sources":["../../../src/operators/topK.ts"],"sourcesContent":["import { MultiSet } from \"../multiset.js\"\nimport { reduce } from \"./reduce.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types\"\nimport type { KeyValue } from \"../types.js\"\n\ninterface TopKOptions {\n limit?: number\n offset?: number\n}\n\n/**\n * Limits the number of results based on a comparator, with optional offset.\n * This works on a keyed stream, where the key is the first element of the tuple\n * The ordering is withing a key group, i.e. elements are sorted within a key group\n * and the limit + offset is applied to that sorted group.\n * To order the entire stream, key by the same value for all elements such as null.\n *\n * @param comparator - A function that compares two elements\n * @param options - An optional object containing limit and offset properties\n * @returns A piped operator that limits the number of results\n */\nexport function topK<\n KType extends T extends KeyValue<infer K, infer _V> ? K : never,\n V1Type extends T extends KeyValue<KType, infer V> ? V : never,\n T,\n>(\n comparator: (a: V1Type, b: V1Type) => number,\n options?: TopKOptions\n): PipedOperator<T, T> {\n const limit = options?.limit ?? Infinity\n const offset = options?.offset ?? 0\n\n return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {\n const reduced = stream.pipe(\n reduce((values) => {\n // `values` is a list of tuples, first element is the value, second is the multiplicity\n const consolidated = new MultiSet(values).consolidate()\n const sortedValues = consolidated\n .getInner()\n .sort((a, b) => comparator(a[0] as V1Type, b[0] as V1Type))\n return sortedValues.slice(offset, offset + limit)\n })\n )\n return reduced as IStreamBuilder<T>\n }\n}\n\n/**\n * Limits the number of results based on a comparator, with optional offset.\n * This works on a keyed stream, where the key is the first element of the tuple\n * The ordering is withing a key group, i.e. elements are sorted within a key group\n * and the limit + offset is applied to that sorted group.\n * To order the entire stream, key by the same value for all elements such as null.\n * Adds the index of the element to the result as [key, [value, index]]\n *\n * @param comparator - A function that compares two elements\n * @param options - An optional object containing limit and offset properties\n * @returns A piped operator that orders the elements and limits the number of results\n */\nexport function topKWithIndex<\n KType extends T extends KeyValue<infer K, infer _V> ? K : never,\n V1Type extends T extends KeyValue<KType, infer V> ? V : never,\n T,\n>(\n comparator: (a: V1Type, b: V1Type) => number,\n options?: TopKOptions\n): PipedOperator<T, KeyValue<KType, [V1Type, number]>> {\n const limit = options?.limit ?? Infinity\n const offset = options?.offset ?? 0\n\n return (\n stream: IStreamBuilder<T>\n ): IStreamBuilder<KeyValue<KType, [V1Type, number]>> => {\n const reduced = stream.pipe(\n reduce<KType, V1Type, [V1Type, number], T>((values) => {\n // `values` is a list of tuples, first element is the value, second is the multiplicity\n const consolidated = new MultiSet(values).consolidate()\n let i = offset\n const sortedValues = consolidated\n .getInner()\n .sort((a, b) => comparator(a[0], b[0]))\n .slice(offset, offset + limit)\n .map(([value, multiplicity]): [[V1Type, number], number] => [\n [value, i++],\n multiplicity,\n ])\n return sortedValues\n })\n )\n return reduced\n }\n}\n"],"names":["reduce","MultiSet"],"mappings":";;;;AAqBO,SAAS,KAKd,YACA,SACqB;AACrB,QAAM,SAAQ,mCAAS,UAAS;AAChC,QAAM,UAAS,mCAAS,WAAU;AAElC,SAAO,CAAC,WAAiD;AACvD,UAAM,UAAU,OAAO;AAAA,MACrBA,OAAAA,OAAO,CAAC,WAAW;AAEjB,cAAM,eAAe,IAAIC,SAAAA,SAAS,MAAM,EAAE,YAAA;AAC1C,cAAM,eAAe,aAClB,SAAA,EACA,KAAK,CAAC,GAAG,MAAM,WAAW,EAAE,CAAC,GAAa,EAAE,CAAC,CAAW,CAAC;AAC5D,eAAO,aAAa,MAAM,QAAQ,SAAS,KAAK;AAAA,MAClD,CAAC;AAAA,IAAA;AAEH,WAAO;AAAA,EACT;AACF;AAcO,SAAS,cAKd,YACA,SACqD;AACrD,QAAM,SAAQ,mCAAS,UAAS;AAChC,QAAM,UAAS,mCAAS,WAAU;AAElC,SAAO,CACL,WACsD;AACtD,UAAM,UAAU,OAAO;AAAA,MACrBD,OAAAA,OAA2C,CAAC,WAAW;AAErD,cAAM,eAAe,IAAIC,SAAAA,SAAS,MAAM,EAAE,YAAA;AAC1C,YAAI,IAAI;AACR,cAAM,eAAe,aAClB,SAAA,EACA,KAAK,CAAC,GAAG,MAAM,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EACrC,MAAM,QAAQ,SAAS,KAAK,EAC5B,IAAI,CAAC,CAAC,OAAO,YAAY,MAAkC;AAAA,UAC1D,CAAC,OAAO,GAAG;AAAA,UACX;AAAA,QAAA,CACD;AACH,eAAO;AAAA,MACT,CAAC;AAAA,IAAA;AAEH,WAAO;AAAA,EACT;AACF;;;"}