@tanstack/db-ivm 0.1.9 → 0.1.10

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 (85) hide show
  1. package/dist/cjs/d2.cjs +25 -49
  2. package/dist/cjs/d2.cjs.map +1 -1
  3. package/dist/cjs/graph.cjs +8 -20
  4. package/dist/cjs/graph.cjs.map +1 -1
  5. package/dist/cjs/indexes.cjs +118 -79
  6. package/dist/cjs/indexes.cjs.map +1 -1
  7. package/dist/cjs/indexes.d.cts +23 -0
  8. package/dist/cjs/multiset.cjs +106 -115
  9. package/dist/cjs/multiset.cjs.map +1 -1
  10. package/dist/cjs/multiset.d.cts +1 -0
  11. package/dist/cjs/operators/debug.cjs +5 -15
  12. package/dist/cjs/operators/debug.cjs.map +1 -1
  13. package/dist/cjs/operators/distinct.cjs +11 -22
  14. package/dist/cjs/operators/distinct.cjs.map +1 -1
  15. package/dist/cjs/operators/filter.cjs +3 -12
  16. package/dist/cjs/operators/filter.cjs.map +1 -1
  17. package/dist/cjs/operators/filterBy.cjs.map +1 -1
  18. package/dist/cjs/operators/filterBy.d.cts +1 -2
  19. package/dist/cjs/operators/groupBy.cjs +1 -2
  20. package/dist/cjs/operators/groupBy.cjs.map +1 -1
  21. package/dist/cjs/operators/join.cjs +104 -93
  22. package/dist/cjs/operators/join.cjs.map +1 -1
  23. package/dist/cjs/operators/join.d.cts +11 -8
  24. package/dist/cjs/operators/map.cjs +3 -12
  25. package/dist/cjs/operators/map.cjs.map +1 -1
  26. package/dist/cjs/operators/orderBy.cjs +10 -10
  27. package/dist/cjs/operators/orderBy.cjs.map +1 -1
  28. package/dist/cjs/operators/orderBy.d.cts +1 -2
  29. package/dist/cjs/operators/output.cjs +3 -12
  30. package/dist/cjs/operators/output.cjs.map +1 -1
  31. package/dist/cjs/operators/reduce.cjs +11 -22
  32. package/dist/cjs/operators/reduce.cjs.map +1 -1
  33. package/dist/cjs/operators/tap.cjs +3 -12
  34. package/dist/cjs/operators/tap.cjs.map +1 -1
  35. package/dist/cjs/operators/topK.cjs +4 -4
  36. package/dist/cjs/operators/topK.cjs.map +1 -1
  37. package/dist/cjs/operators/topK.d.cts +1 -2
  38. package/dist/cjs/operators/topKWithFractionalIndex.cjs +56 -75
  39. package/dist/cjs/operators/topKWithFractionalIndex.cjs.map +1 -1
  40. package/dist/esm/d2.js +25 -49
  41. package/dist/esm/d2.js.map +1 -1
  42. package/dist/esm/graph.js +8 -20
  43. package/dist/esm/graph.js.map +1 -1
  44. package/dist/esm/indexes.d.ts +23 -0
  45. package/dist/esm/indexes.js +118 -79
  46. package/dist/esm/indexes.js.map +1 -1
  47. package/dist/esm/multiset.d.ts +1 -0
  48. package/dist/esm/multiset.js +106 -115
  49. package/dist/esm/multiset.js.map +1 -1
  50. package/dist/esm/operators/debug.js +5 -15
  51. package/dist/esm/operators/debug.js.map +1 -1
  52. package/dist/esm/operators/distinct.js +11 -22
  53. package/dist/esm/operators/distinct.js.map +1 -1
  54. package/dist/esm/operators/filter.js +3 -12
  55. package/dist/esm/operators/filter.js.map +1 -1
  56. package/dist/esm/operators/filterBy.d.ts +1 -2
  57. package/dist/esm/operators/filterBy.js.map +1 -1
  58. package/dist/esm/operators/groupBy.js +1 -2
  59. package/dist/esm/operators/groupBy.js.map +1 -1
  60. package/dist/esm/operators/join.d.ts +11 -8
  61. package/dist/esm/operators/join.js +104 -93
  62. package/dist/esm/operators/join.js.map +1 -1
  63. package/dist/esm/operators/map.js +3 -12
  64. package/dist/esm/operators/map.js.map +1 -1
  65. package/dist/esm/operators/orderBy.d.ts +1 -2
  66. package/dist/esm/operators/orderBy.js +10 -10
  67. package/dist/esm/operators/orderBy.js.map +1 -1
  68. package/dist/esm/operators/output.js +3 -12
  69. package/dist/esm/operators/output.js.map +1 -1
  70. package/dist/esm/operators/reduce.js +11 -22
  71. package/dist/esm/operators/reduce.js.map +1 -1
  72. package/dist/esm/operators/tap.js +3 -12
  73. package/dist/esm/operators/tap.js.map +1 -1
  74. package/dist/esm/operators/topK.d.ts +1 -2
  75. package/dist/esm/operators/topK.js +4 -4
  76. package/dist/esm/operators/topK.js.map +1 -1
  77. package/dist/esm/operators/topKWithFractionalIndex.js +56 -75
  78. package/dist/esm/operators/topKWithFractionalIndex.js.map +1 -1
  79. package/package.json +1 -1
  80. package/src/indexes.ts +54 -0
  81. package/src/multiset.ts +6 -0
  82. package/src/operators/filterBy.ts +1 -2
  83. package/src/operators/join.ts +249 -139
  84. package/src/operators/orderBy.ts +1 -2
  85. package/src/operators/topK.ts +1 -2
package/dist/cjs/d2.cjs CHANGED
@@ -1,58 +1,45 @@
1
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 __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
10
- var __privateWrapper = (obj, member, setter, getter) => ({
11
- set _(value) {
12
- __privateSet(obj, member, value, setter);
13
- },
14
- get _() {
15
- return __privateGet(obj, member, getter);
16
- }
17
- });
18
- var _operators, _nextOperatorId, _finalized, _D2_instances, checkNotFinalized_fn, _graph, _writer;
19
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
20
3
  const graph = require("./graph.cjs");
21
4
  class D2 {
5
+ #operators = [];
6
+ #nextOperatorId = 0;
7
+ #finalized = false;
22
8
  constructor() {
23
- __privateAdd(this, _D2_instances);
24
- __privateAdd(this, _operators, []);
25
- __privateAdd(this, _nextOperatorId, 0);
26
- __privateAdd(this, _finalized, false);
9
+ }
10
+ #checkNotFinalized() {
11
+ if (this.#finalized) {
12
+ throw new Error(`Graph already finalized`);
13
+ }
27
14
  }
28
15
  getNextOperatorId() {
29
- __privateMethod(this, _D2_instances, checkNotFinalized_fn).call(this);
30
- return __privateWrapper(this, _nextOperatorId)._++;
16
+ this.#checkNotFinalized();
17
+ return this.#nextOperatorId++;
31
18
  }
32
19
  newInput() {
33
- __privateMethod(this, _D2_instances, checkNotFinalized_fn).call(this);
20
+ this.#checkNotFinalized();
34
21
  const writer = new graph.DifferenceStreamWriter();
35
22
  const streamBuilder = new RootStreamBuilder(this, writer);
36
23
  return streamBuilder;
37
24
  }
38
25
  addOperator(operator) {
39
- __privateMethod(this, _D2_instances, checkNotFinalized_fn).call(this);
40
- __privateGet(this, _operators).push(operator);
26
+ this.#checkNotFinalized();
27
+ this.#operators.push(operator);
41
28
  }
42
29
  finalize() {
43
- __privateMethod(this, _D2_instances, checkNotFinalized_fn).call(this);
44
- __privateSet(this, _finalized, true);
30
+ this.#checkNotFinalized();
31
+ this.#finalized = true;
45
32
  }
46
33
  step() {
47
- if (!__privateGet(this, _finalized)) {
34
+ if (!this.#finalized) {
48
35
  throw new Error(`Graph not finalized`);
49
36
  }
50
- for (const op of __privateGet(this, _operators)) {
37
+ for (const op of this.#operators) {
51
38
  op.run();
52
39
  }
53
40
  }
54
41
  pendingWork() {
55
- return __privateGet(this, _operators).some((op) => op.hasPendingWork());
42
+ return this.#operators.some((op) => op.hasPendingWork());
56
43
  }
57
44
  run() {
58
45
  while (this.pendingWork()) {
@@ -60,30 +47,21 @@ class D2 {
60
47
  }
61
48
  }
62
49
  }
63
- _operators = new WeakMap();
64
- _nextOperatorId = new WeakMap();
65
- _finalized = new WeakMap();
66
- _D2_instances = new WeakSet();
67
- checkNotFinalized_fn = function() {
68
- if (__privateGet(this, _finalized)) {
69
- throw new Error(`Graph already finalized`);
70
- }
71
- };
72
50
  class StreamBuilder {
51
+ #graph;
52
+ #writer;
73
53
  constructor(graph2, writer) {
74
- __privateAdd(this, _graph);
75
- __privateAdd(this, _writer);
76
- __privateSet(this, _graph, graph2);
77
- __privateSet(this, _writer, writer);
54
+ this.#graph = graph2;
55
+ this.#writer = writer;
78
56
  }
79
57
  connectReader() {
80
- return __privateGet(this, _writer).newReader();
58
+ return this.#writer.newReader();
81
59
  }
82
60
  get writer() {
83
- return __privateGet(this, _writer);
61
+ return this.#writer;
84
62
  }
85
63
  get graph() {
86
- return __privateGet(this, _graph);
64
+ return this.#graph;
87
65
  }
88
66
  pipe(...operators) {
89
67
  return operators.reduce((stream, operator) => {
@@ -91,8 +69,6 @@ class StreamBuilder {
91
69
  }, this);
92
70
  }
93
71
  }
94
- _graph = new WeakMap();
95
- _writer = new WeakMap();
96
72
  class RootStreamBuilder extends StreamBuilder {
97
73
  sendData(collection) {
98
74
  this.writer.sendData(collection);
@@ -1 +1 @@
1
- {"version":3,"file":"d2.cjs","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 #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 return streamBuilder\n }\n\n addOperator(operator: UnaryOperator<any> | BinaryOperator<any>): void {\n this.#checkNotFinalized()\n this.#operators.push(operator)\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":["DifferenceStreamWriter","graph"],"mappings":";;;;;;;;;;;;;;;;;;;;AASO,MAAM,GAAkB;AAAA,EAK7B,cAAc;AALT;AACL,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,IAAIA,6BAAA;AAEnB,UAAM,gBAAgB,IAAI,kBAAqB,MAAM,MAAM;AAC3D,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,UAA0D;AACpE,0BAAK,qCAAL;AACA,uBAAK,YAAW,KAAK,QAAQ;AAAA,EAC/B;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;AArDE;AACA;AACA;AAHK;AAOL,uBAAA,WAA2B;AACzB,MAAI,mBAAK,aAAY;AACnB,UAAM,IAAI,MAAM,yBAAyB;AAAA,EAC3C;AACF;AA6CK,MAAM,cAA8C;AAAA,EAIzD,YAAYC,QAAY,QAAmC;AAH3D;AACA;AAGE,uBAAK,QAASA;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;;;;"}
1
+ {"version":3,"file":"d2.cjs","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 #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 return streamBuilder\n }\n\n addOperator(operator: UnaryOperator<any> | BinaryOperator<any>): void {\n this.#checkNotFinalized()\n this.#operators.push(operator)\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":["DifferenceStreamWriter","graph"],"mappings":";;;AASO,MAAM,GAAkB;AAAA,EAC7B,aAA8D,CAAA;AAAA,EAC9D,kBAAkB;AAAA,EAClB,aAAa;AAAA,EAEb,cAAc;AAAA,EAAC;AAAA,EAEf,qBAA2B;AACzB,QAAI,KAAK,YAAY;AACnB,YAAM,IAAI,MAAM,yBAAyB;AAAA,IAC3C;AAAA,EACF;AAAA,EAEA,oBAA4B;AAC1B,SAAK,mBAAA;AACL,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,WAAoC;AAClC,SAAK,mBAAA;AACL,UAAM,SAAS,IAAIA,6BAAA;AAEnB,UAAM,gBAAgB,IAAI,kBAAqB,MAAM,MAAM;AAC3D,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,UAA0D;AACpE,SAAK,mBAAA;AACL,SAAK,WAAW,KAAK,QAAQ;AAAA,EAC/B;AAAA,EAEA,WAAW;AACT,SAAK,mBAAA;AACL,SAAK,aAAa;AAAA,EACpB;AAAA,EAEA,OAAa;AACX,QAAI,CAAC,KAAK,YAAY;AACpB,YAAM,IAAI,MAAM,qBAAqB;AAAA,IACvC;AACA,eAAW,MAAM,KAAK,YAAY;AAChC,SAAG,IAAA;AAAA,IACL;AAAA,EACF;AAAA,EAEA,cAAuB;AACrB,WAAO,KAAK,WAAW,KAAK,CAAC,OAAO,GAAG,gBAAgB;AAAA,EACzD;AAAA,EAEA,MAAY;AACV,WAAO,KAAK,eAAe;AACzB,WAAK,KAAA;AAAA,IACP;AAAA,EACF;AACF;AAEO,MAAM,cAA8C;AAAA,EACzD;AAAA,EACA;AAAA,EAEA,YAAYC,QAAY,QAAmC;AACzD,SAAK,SAASA;AACd,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,gBAA2C;AACzC,WAAO,KAAK,QAAQ,UAAA;AAAA,EACtB;AAAA,EAEA,IAAI,SAAoC;AACtC,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,QAAa;AACf,WAAO,KAAK;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;AAEO,MAAM,0BAA6B,cAAiB;AAAA,EACzD,SAAS,YAAkD;AACzD,SAAK,OAAO,SAAS,UAAU;AAAA,EACjC;AACF;;;;"}
@@ -1,48 +1,36 @@
1
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 _queue, _queues;
10
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
11
3
  const multiset = require("./multiset.cjs");
12
4
  class DifferenceStreamReader {
5
+ #queue;
13
6
  constructor(queue) {
14
- __privateAdd(this, _queue);
15
- __privateSet(this, _queue, queue);
7
+ this.#queue = queue;
16
8
  }
17
9
  drain() {
18
- const out = [...__privateGet(this, _queue)].reverse();
19
- __privateGet(this, _queue).length = 0;
10
+ const out = [...this.#queue].reverse();
11
+ this.#queue.length = 0;
20
12
  return out;
21
13
  }
22
14
  isEmpty() {
23
- return __privateGet(this, _queue).length === 0;
15
+ return this.#queue.length === 0;
24
16
  }
25
17
  }
26
- _queue = new WeakMap();
27
18
  class DifferenceStreamWriter {
28
- constructor() {
29
- __privateAdd(this, _queues, []);
30
- }
19
+ #queues = [];
31
20
  sendData(collection) {
32
21
  if (!(collection instanceof multiset.MultiSet)) {
33
22
  collection = new multiset.MultiSet(collection);
34
23
  }
35
- for (const q of __privateGet(this, _queues)) {
24
+ for (const q of this.#queues) {
36
25
  q.unshift(collection);
37
26
  }
38
27
  }
39
28
  newReader() {
40
29
  const q = [];
41
- __privateGet(this, _queues).push(q);
30
+ this.#queues.push(q);
42
31
  return new DifferenceStreamReader(q);
43
32
  }
44
33
  }
45
- _queues = new WeakMap();
46
34
  class Operator {
47
35
  constructor(id, inputs, output) {
48
36
  this.id = id;
@@ -1 +1 @@
1
- {"version":3,"file":"graph.cjs","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":["MultiSet"],"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,sBAAsBA,SAAAA,WAAW;AACrC,mBAAa,IAAIA,SAAAA,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;;;;;;;"}
1
+ {"version":3,"file":"graph.cjs","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":["MultiSet"],"mappings":";;;AAWO,MAAM,uBAAgE;AAAA,EAC3E;AAAA,EAEA,YAAY,OAA2B;AACrC,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,QAA4B;AAC1B,UAAM,MAAM,CAAC,GAAG,KAAK,MAAM,EAAE,QAAA;AAC7B,SAAK,OAAO,SAAS;AACrB,WAAO;AAAA,EACT;AAAA,EAEA,UAAmB;AACjB,WAAO,KAAK,OAAO,WAAW;AAAA,EAChC;AACF;AAKO,MAAM,uBAAgE;AAAA,EAC3E,UAAqC,CAAA;AAAA,EAErC,SAAS,YAAkD;AACzD,QAAI,EAAE,sBAAsBA,SAAAA,WAAW;AACrC,mBAAa,IAAIA,SAAAA,SAAS,UAAU;AAAA,IACtC;AAEA,eAAW,KAAK,KAAK,SAAS;AAC5B,QAAE,QAAQ,UAAU;AAAA,IACtB;AAAA,EACF;AAAA,EAEA,YAAuC;AACrC,UAAM,IAAwB,CAAA;AAC9B,SAAK,QAAQ,KAAK,CAAC;AACnB,WAAO,IAAI,uBAAuB,CAAC;AAAA,EACrC;AACF;AAMO,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;;;;;;;"}
@@ -1,13 +1,4 @@
1
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 __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
10
- var _inner, _Index_instances, handleSingleValueTransition_fn;
11
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
12
3
  const multiset = require("./multiset.cjs");
13
4
  const hash = require("./hashing/hash.cjs");
@@ -76,20 +67,36 @@ class ValueMap extends Map {
76
67
  }
77
68
  }
78
69
  class Index {
70
+ /*
71
+ * This index maintains a nested map of keys -> (value, multiplicities), where:
72
+ * - initially the values are stored against the key as a single value tuple
73
+ * - when a key gets additional values, the values are stored against the key in a
74
+ * prefix map
75
+ * - the prefix is extract where possible from values that are structured as
76
+ * [rowPrimaryKey, rowValue], as they are in the Tanstack DB query pipeline.
77
+ * - only when there are multiple values for a given prefix do we fall back to a
78
+ * hash to identify identical values, storing them in a third level value map.
79
+ */
80
+ #inner;
81
+ #consolidatedMultiplicity = /* @__PURE__ */ new Map();
82
+ // sum of multiplicities per key
79
83
  constructor() {
80
- __privateAdd(this, _Index_instances);
81
- /*
82
- * This index maintains a nested map of keys -> (value, multiplicities), where:
83
- * - initially the values are stored against the key as a single value tuple
84
- * - when a key gets additional values, the values are stored against the key in a
85
- * prefix map
86
- * - the prefix is extract where possible from values that are structured as
87
- * [rowPrimaryKey, rowValue], as they are in the Tanstack DB query pipeline.
88
- * - only when there are multiple values for a given prefix do we fall back to a
89
- * hash to identify identical values, storing them in a third level value map.
90
- */
91
- __privateAdd(this, _inner);
92
- __privateSet(this, _inner, /* @__PURE__ */ new Map());
84
+ this.#inner = /* @__PURE__ */ new Map();
85
+ }
86
+ /**
87
+ * Create an Index from multiple MultiSet messages.
88
+ * @param messages - Array of MultiSet messages to build the index from.
89
+ * @returns A new Index containing all the data from the messages.
90
+ */
91
+ static fromMultiSets(messages) {
92
+ const index = new Index();
93
+ for (const message of messages) {
94
+ for (const [item, multiplicity] of message.getInner()) {
95
+ const [key, value] = item;
96
+ index.addValue(key, [value, multiplicity]);
97
+ }
98
+ }
99
+ return index;
93
100
  }
94
101
  /**
95
102
  * This method returns a string representation of the index.
@@ -107,7 +114,7 @@ class Index {
107
114
  * The size of the index.
108
115
  */
109
116
  get size() {
110
- return __privateGet(this, _inner).size;
117
+ return this.#inner.size;
111
118
  }
112
119
  /**
113
120
  * This method checks if the index has a given key.
@@ -115,7 +122,30 @@ class Index {
115
122
  * @returns True if the index has the key, false otherwise.
116
123
  */
117
124
  has(key) {
118
- return __privateGet(this, _inner).has(key);
125
+ return this.#inner.has(key);
126
+ }
127
+ /**
128
+ * Check if a key has presence (non-zero consolidated multiplicity).
129
+ * @param key - The key to check.
130
+ * @returns True if the key has non-zero consolidated multiplicity, false otherwise.
131
+ */
132
+ hasPresence(key) {
133
+ return (this.#consolidatedMultiplicity.get(key) || 0) !== 0;
134
+ }
135
+ /**
136
+ * Get the consolidated multiplicity (sum of multiplicities) for a key.
137
+ * @param key - The key to get the consolidated multiplicity for.
138
+ * @returns The consolidated multiplicity for the key.
139
+ */
140
+ getConsolidatedMultiplicity(key) {
141
+ return this.#consolidatedMultiplicity.get(key) || 0;
142
+ }
143
+ /**
144
+ * Get all keys that have presence (non-zero consolidated multiplicity).
145
+ * @returns An iterator of keys with non-zero consolidated multiplicity.
146
+ */
147
+ getPresenceKeys() {
148
+ return this.#consolidatedMultiplicity.keys();
119
149
  }
120
150
  /**
121
151
  * This method returns all values for a given key.
@@ -131,7 +161,7 @@ class Index {
131
161
  * @returns An iterator of value tuples [value, multiplicity].
132
162
  */
133
163
  *getIterator(key) {
134
- const mapOrSingleValue = __privateGet(this, _inner).get(key);
164
+ const mapOrSingleValue = this.#inner.get(key);
135
165
  if (isSingleValue(mapOrSingleValue)) {
136
166
  yield mapOrSingleValue;
137
167
  } else if (mapOrSingleValue === void 0) {
@@ -157,7 +187,7 @@ class Index {
157
187
  * @returns An iterable of all key-value pairs (and their multiplicities) in the index.
158
188
  */
159
189
  *entries() {
160
- for (const key of __privateGet(this, _inner).keys()) {
190
+ for (const key of this.#inner.keys()) {
161
191
  for (const valueTuple of this.getIterator(key)) {
162
192
  yield [key, valueTuple];
163
193
  }
@@ -170,7 +200,7 @@ class Index {
170
200
  * @returns An iterator of all *keys* in the index and their corresponding value iterator.
171
201
  */
172
202
  *entriesIterators() {
173
- for (const key of __privateGet(this, _inner).keys()) {
203
+ for (const key of this.#inner.keys()) {
174
204
  yield [key, this.getIterator(key)];
175
205
  }
176
206
  }
@@ -182,13 +212,24 @@ class Index {
182
212
  addValue(key, valueTuple) {
183
213
  const [value, multiplicity] = valueTuple;
184
214
  if (multiplicity === 0) return;
185
- const mapOrSingleValue = __privateGet(this, _inner).get(key);
215
+ const newConsolidatedMultiplicity = (this.#consolidatedMultiplicity.get(key) || 0) + multiplicity;
216
+ if (newConsolidatedMultiplicity === 0) {
217
+ this.#consolidatedMultiplicity.delete(key);
218
+ } else {
219
+ this.#consolidatedMultiplicity.set(key, newConsolidatedMultiplicity);
220
+ }
221
+ const mapOrSingleValue = this.#inner.get(key);
186
222
  if (mapOrSingleValue === void 0) {
187
- __privateGet(this, _inner).set(key, valueTuple);
223
+ this.#inner.set(key, valueTuple);
188
224
  return;
189
225
  }
190
226
  if (isSingleValue(mapOrSingleValue)) {
191
- __privateMethod(this, _Index_instances, handleSingleValueTransition_fn).call(this, key, mapOrSingleValue, value, multiplicity);
227
+ this.#handleSingleValueTransition(
228
+ key,
229
+ mapOrSingleValue,
230
+ value,
231
+ multiplicity
232
+ );
192
233
  return;
193
234
  }
194
235
  if (mapOrSingleValue instanceof ValueMap) {
@@ -197,20 +238,64 @@ class Index {
197
238
  const prefixMap = new PrefixMap();
198
239
  prefixMap.set(NO_PREFIX, mapOrSingleValue);
199
240
  prefixMap.set(prefix, valueTuple);
200
- __privateGet(this, _inner).set(key, prefixMap);
241
+ this.#inner.set(key, prefixMap);
201
242
  } else {
202
243
  const isEmpty = mapOrSingleValue.addValue(value, multiplicity);
203
244
  if (isEmpty) {
204
- __privateGet(this, _inner).delete(key);
245
+ this.#inner.delete(key);
205
246
  }
206
247
  }
207
248
  } else {
208
249
  const isEmpty = mapOrSingleValue.addValue(value, multiplicity);
209
250
  if (isEmpty) {
210
- __privateGet(this, _inner).delete(key);
251
+ this.#inner.delete(key);
211
252
  }
212
253
  }
213
254
  }
255
+ /**
256
+ * Handle the transition from a single value to either a ValueMap or PrefixMap
257
+ */
258
+ #handleSingleValueTransition(key, currentSingleValue, newValue, multiplicity) {
259
+ const [currentValue, currentMultiplicity] = currentSingleValue;
260
+ if (currentValue === newValue) {
261
+ const newMultiplicity = currentMultiplicity + multiplicity;
262
+ if (newMultiplicity === 0) {
263
+ this.#inner.delete(key);
264
+ } else {
265
+ this.#inner.set(key, [newValue, newMultiplicity]);
266
+ }
267
+ return;
268
+ }
269
+ const newPrefix = getPrefix(newValue);
270
+ const currentPrefix = getPrefix(currentValue);
271
+ if (currentPrefix === newPrefix && (currentValue === newValue || hash.hash(currentValue) === hash.hash(newValue))) {
272
+ const newMultiplicity = currentMultiplicity + multiplicity;
273
+ if (newMultiplicity === 0) {
274
+ this.#inner.delete(key);
275
+ } else {
276
+ this.#inner.set(key, [newValue, newMultiplicity]);
277
+ }
278
+ return;
279
+ }
280
+ if (currentPrefix === NO_PREFIX && newPrefix === NO_PREFIX) {
281
+ const valueMap = new ValueMap();
282
+ valueMap.set(hash.hash(currentValue), currentSingleValue);
283
+ valueMap.set(hash.hash(newValue), [newValue, multiplicity]);
284
+ this.#inner.set(key, valueMap);
285
+ } else {
286
+ const prefixMap = new PrefixMap();
287
+ if (currentPrefix === newPrefix) {
288
+ const valueMap = new ValueMap();
289
+ valueMap.set(hash.hash(currentValue), currentSingleValue);
290
+ valueMap.set(hash.hash(newValue), [newValue, multiplicity]);
291
+ prefixMap.set(currentPrefix, valueMap);
292
+ } else {
293
+ prefixMap.set(currentPrefix, currentSingleValue);
294
+ prefixMap.set(newPrefix, [newValue, multiplicity]);
295
+ }
296
+ this.#inner.set(key, prefixMap);
297
+ }
298
+ }
214
299
  /**
215
300
  * This method appends another index to the current index.
216
301
  * @param other - The index to append to the current index.
@@ -255,52 +340,6 @@ class Index {
255
340
  return new multiset.MultiSet(result);
256
341
  }
257
342
  }
258
- _inner = new WeakMap();
259
- _Index_instances = new WeakSet();
260
- /**
261
- * Handle the transition from a single value to either a ValueMap or PrefixMap
262
- */
263
- handleSingleValueTransition_fn = function(key, currentSingleValue, newValue, multiplicity) {
264
- const [currentValue, currentMultiplicity] = currentSingleValue;
265
- if (currentValue === newValue) {
266
- const newMultiplicity = currentMultiplicity + multiplicity;
267
- if (newMultiplicity === 0) {
268
- __privateGet(this, _inner).delete(key);
269
- } else {
270
- __privateGet(this, _inner).set(key, [newValue, newMultiplicity]);
271
- }
272
- return;
273
- }
274
- const newPrefix = getPrefix(newValue);
275
- const currentPrefix = getPrefix(currentValue);
276
- if (currentPrefix === newPrefix && (currentValue === newValue || hash.hash(currentValue) === hash.hash(newValue))) {
277
- const newMultiplicity = currentMultiplicity + multiplicity;
278
- if (newMultiplicity === 0) {
279
- __privateGet(this, _inner).delete(key);
280
- } else {
281
- __privateGet(this, _inner).set(key, [newValue, newMultiplicity]);
282
- }
283
- return;
284
- }
285
- if (currentPrefix === NO_PREFIX && newPrefix === NO_PREFIX) {
286
- const valueMap = new ValueMap();
287
- valueMap.set(hash.hash(currentValue), currentSingleValue);
288
- valueMap.set(hash.hash(newValue), [newValue, multiplicity]);
289
- __privateGet(this, _inner).set(key, valueMap);
290
- } else {
291
- const prefixMap = new PrefixMap();
292
- if (currentPrefix === newPrefix) {
293
- const valueMap = new ValueMap();
294
- valueMap.set(hash.hash(currentValue), currentSingleValue);
295
- valueMap.set(hash.hash(newValue), [newValue, multiplicity]);
296
- prefixMap.set(currentPrefix, valueMap);
297
- } else {
298
- prefixMap.set(currentPrefix, currentSingleValue);
299
- prefixMap.set(newPrefix, [newValue, multiplicity]);
300
- }
301
- __privateGet(this, _inner).set(key, prefixMap);
302
- }
303
- };
304
343
  function getPrefix(value) {
305
344
  if (Array.isArray(value) && (typeof value[0] === `string` || typeof value[0] === `number` || typeof value[0] === `bigint`)) {
306
345
  return value[0];