@tanstack/db-ivm 0.1.6 → 0.1.8

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 (104) hide show
  1. package/dist/cjs/d2.cjs +1 -8
  2. package/dist/cjs/d2.cjs.map +1 -1
  3. package/dist/cjs/d2.d.cts +0 -1
  4. package/dist/cjs/indexes.cjs +243 -85
  5. package/dist/cjs/indexes.cjs.map +1 -1
  6. package/dist/cjs/indexes.d.cts +58 -7
  7. package/dist/cjs/operators/concat.cjs +0 -1
  8. package/dist/cjs/operators/concat.cjs.map +1 -1
  9. package/dist/cjs/operators/consolidate.cjs +0 -1
  10. package/dist/cjs/operators/consolidate.cjs.map +1 -1
  11. package/dist/cjs/operators/count.cjs +0 -1
  12. package/dist/cjs/operators/count.cjs.map +1 -1
  13. package/dist/cjs/operators/debug.cjs +0 -1
  14. package/dist/cjs/operators/debug.cjs.map +1 -1
  15. package/dist/cjs/operators/distinct.cjs +2 -3
  16. package/dist/cjs/operators/distinct.cjs.map +1 -1
  17. package/dist/cjs/operators/distinct.d.cts +6 -4
  18. package/dist/cjs/operators/filter.cjs +0 -1
  19. package/dist/cjs/operators/filter.cjs.map +1 -1
  20. package/dist/cjs/operators/join.cjs +0 -1
  21. package/dist/cjs/operators/join.cjs.map +1 -1
  22. package/dist/cjs/operators/map.cjs +0 -1
  23. package/dist/cjs/operators/map.cjs.map +1 -1
  24. package/dist/cjs/operators/negate.cjs +0 -1
  25. package/dist/cjs/operators/negate.cjs.map +1 -1
  26. package/dist/cjs/operators/output.cjs +0 -1
  27. package/dist/cjs/operators/output.cjs.map +1 -1
  28. package/dist/cjs/operators/reduce.cjs +0 -1
  29. package/dist/cjs/operators/reduce.cjs.map +1 -1
  30. package/dist/cjs/operators/tap.cjs +0 -1
  31. package/dist/cjs/operators/tap.cjs.map +1 -1
  32. package/dist/cjs/operators/topKWithFractionalIndex.cjs +0 -1
  33. package/dist/cjs/operators/topKWithFractionalIndex.cjs.map +1 -1
  34. package/dist/cjs/types.d.cts +0 -1
  35. package/dist/cjs/utils.cjs +0 -12
  36. package/dist/cjs/utils.cjs.map +1 -1
  37. package/dist/esm/d2.d.ts +0 -1
  38. package/dist/esm/d2.js +1 -8
  39. package/dist/esm/d2.js.map +1 -1
  40. package/dist/esm/indexes.d.ts +58 -7
  41. package/dist/esm/indexes.js +243 -85
  42. package/dist/esm/indexes.js.map +1 -1
  43. package/dist/esm/operators/concat.js +0 -1
  44. package/dist/esm/operators/concat.js.map +1 -1
  45. package/dist/esm/operators/consolidate.js +0 -1
  46. package/dist/esm/operators/consolidate.js.map +1 -1
  47. package/dist/esm/operators/count.js +0 -1
  48. package/dist/esm/operators/count.js.map +1 -1
  49. package/dist/esm/operators/debug.js +0 -1
  50. package/dist/esm/operators/debug.js.map +1 -1
  51. package/dist/esm/operators/distinct.d.ts +6 -4
  52. package/dist/esm/operators/distinct.js +2 -3
  53. package/dist/esm/operators/distinct.js.map +1 -1
  54. package/dist/esm/operators/filter.js +0 -1
  55. package/dist/esm/operators/filter.js.map +1 -1
  56. package/dist/esm/operators/join.js +0 -1
  57. package/dist/esm/operators/join.js.map +1 -1
  58. package/dist/esm/operators/map.js +0 -1
  59. package/dist/esm/operators/map.js.map +1 -1
  60. package/dist/esm/operators/negate.js +0 -1
  61. package/dist/esm/operators/negate.js.map +1 -1
  62. package/dist/esm/operators/output.js +0 -1
  63. package/dist/esm/operators/output.js.map +1 -1
  64. package/dist/esm/operators/reduce.js +0 -1
  65. package/dist/esm/operators/reduce.js.map +1 -1
  66. package/dist/esm/operators/tap.js +0 -1
  67. package/dist/esm/operators/tap.js.map +1 -1
  68. package/dist/esm/operators/topKWithFractionalIndex.js +0 -1
  69. package/dist/esm/operators/topKWithFractionalIndex.js.map +1 -1
  70. package/dist/esm/types.d.ts +0 -1
  71. package/dist/esm/utils.js +1 -13
  72. package/dist/esm/utils.js.map +1 -1
  73. package/package.json +1 -1
  74. package/src/d2.ts +0 -7
  75. package/src/indexes.ts +365 -90
  76. package/src/operators/concat.ts +0 -1
  77. package/src/operators/consolidate.ts +0 -1
  78. package/src/operators/count.ts +0 -1
  79. package/src/operators/debug.ts +0 -1
  80. package/src/operators/distinct.ts +13 -9
  81. package/src/operators/filter.ts +0 -1
  82. package/src/operators/join.ts +0 -1
  83. package/src/operators/map.ts +0 -1
  84. package/src/operators/negate.ts +0 -1
  85. package/src/operators/output.ts +0 -1
  86. package/src/operators/reduce.ts +0 -1
  87. package/src/operators/tap.ts +0 -1
  88. package/src/operators/topKWithFractionalIndex.ts +0 -1
  89. package/src/operators/topKWithFractionalIndexBTree.ts +0 -1
  90. package/src/types.ts +0 -1
  91. package/dist/cjs/hashIndex.cjs +0 -83
  92. package/dist/cjs/hashIndex.cjs.map +0 -1
  93. package/dist/cjs/hashIndex.d.cts +0 -25
  94. package/dist/cjs/valueIndex.cjs +0 -74
  95. package/dist/cjs/valueIndex.cjs.map +0 -1
  96. package/dist/cjs/valueIndex.d.cts +0 -17
  97. package/dist/esm/hashIndex.d.ts +0 -25
  98. package/dist/esm/hashIndex.js +0 -83
  99. package/dist/esm/hashIndex.js.map +0 -1
  100. package/dist/esm/valueIndex.d.ts +0 -17
  101. package/dist/esm/valueIndex.js +0 -74
  102. package/dist/esm/valueIndex.js.map +0 -1
  103. package/src/hashIndex.ts +0 -94
  104. package/src/valueIndex.ts +0 -78
@@ -4,21 +4,25 @@ import { hash } from "../hashing/index.js"
4
4
  import { MultiSet } from "../multiset.js"
5
5
  import type { Hash } from "../hashing/index.js"
6
6
  import type { DifferenceStreamReader } from "../graph.js"
7
- import type { IStreamBuilder } from "../types.js"
7
+ import type { IStreamBuilder, KeyValue } from "../types.js"
8
8
 
9
9
  type Multiplicity = number
10
10
 
11
+ type GetValue<T> = T extends KeyValue<any, infer V> ? V : never
12
+
11
13
  /**
12
14
  * Operator that removes duplicates
13
15
  */
14
- export class DistinctOperator<T> extends UnaryOperator<T> {
16
+ export class DistinctOperator<
17
+ T extends KeyValue<any, any>,
18
+ > extends UnaryOperator<T, KeyValue<number, GetValue<T>>> {
15
19
  #by: (value: T) => any
16
20
  #values: Map<Hash, Multiplicity> // keeps track of the number of times each value has been seen
17
21
 
18
22
  constructor(
19
23
  id: number,
20
24
  input: DifferenceStreamReader<T>,
21
- output: DifferenceStreamWriter<T>,
25
+ output: DifferenceStreamWriter<KeyValue<number, GetValue<T>>>,
22
26
  by: (value: T) => any = (value: T) => value
23
27
  ) {
24
28
  super(id, input, output)
@@ -39,12 +43,11 @@ export class DistinctOperator<T> extends UnaryOperator<T> {
39
43
  this.#values.get(hashedValue) ??
40
44
  0
41
45
  const newMultiplicity = oldMultiplicity + diff
42
-
43
46
  updatedValues.set(hashedValue, [newMultiplicity, value])
44
47
  }
45
48
  }
46
49
 
47
- const result: Array<[T, number]> = []
50
+ const result: Array<[KeyValue<number, GetValue<T>>, number]> = []
48
51
 
49
52
  // Check which values became visible or disappeared
50
53
  for (const [
@@ -62,11 +65,11 @@ export class DistinctOperator<T> extends UnaryOperator<T> {
62
65
  if (oldMultiplicity <= 0 && newMultiplicity > 0) {
63
66
  // The value wasn't present in the stream
64
67
  // but with this change it is now present in the stream
65
- result.push([value, 1])
68
+ result.push([[hash(this.#by(value)), value[1]], 1])
66
69
  } else if (oldMultiplicity > 0 && newMultiplicity <= 0) {
67
70
  // The value was present in the stream
68
71
  // but with this change it is no longer present in the stream
69
- result.push([value, -1])
72
+ result.push([[hash(this.#by(value)), value[1]], -1])
70
73
  }
71
74
  }
72
75
 
@@ -79,7 +82,9 @@ export class DistinctOperator<T> extends UnaryOperator<T> {
79
82
  /**
80
83
  * Removes duplicate values
81
84
  */
82
- export function distinct<T>(by: (value: T) => any = (value: T) => value) {
85
+ export function distinct<T extends KeyValue<any, any>>(
86
+ by: (value: T) => any = (value: T) => value
87
+ ) {
83
88
  return (stream: IStreamBuilder<T>): IStreamBuilder<T> => {
84
89
  const output = new StreamBuilder<T>(
85
90
  stream.graph,
@@ -92,7 +97,6 @@ export function distinct<T>(by: (value: T) => any = (value: T) => value) {
92
97
  by
93
98
  )
94
99
  stream.graph.addOperator(operator)
95
- stream.graph.addStream(output.connectReader())
96
100
  return output
97
101
  }
98
102
  }
@@ -42,7 +42,6 @@ export function filter<T>(f: (data: T) => boolean): PipedOperator<T, T> {
42
42
  f
43
43
  )
44
44
  stream.graph.addOperator(operator)
45
- stream.graph.addStream(output.connectReader())
46
45
  return output
47
46
  }
48
47
  }
@@ -149,7 +149,6 @@ export function innerJoin<
149
149
  output.writer
150
150
  )
151
151
  stream.graph.addOperator(operator)
152
- stream.graph.addStream(output.connectReader())
153
152
  return output
154
153
  }
155
154
  }
@@ -42,7 +42,6 @@ export function map<T, O>(f: (data: T) => O): PipedOperator<T, O> {
42
42
  f
43
43
  )
44
44
  stream.graph.addOperator(operator)
45
- stream.graph.addStream(output.connectReader())
46
45
  return output
47
46
  }
48
47
  }
@@ -27,7 +27,6 @@ export function negate<T>(): PipedOperator<T, T> {
27
27
  output.writer
28
28
  )
29
29
  stream.graph.addOperator(operator)
30
- stream.graph.addStream(output.connectReader())
31
30
  return output
32
31
  }
33
32
  }
@@ -47,7 +47,6 @@ export function output<T>(
47
47
  fn
48
48
  )
49
49
  stream.graph.addOperator(operator)
50
- stream.graph.addStream(outputStream.connectReader())
51
50
  return outputStream
52
51
  }
53
52
  }
@@ -118,7 +118,6 @@ export function reduce<
118
118
  f
119
119
  )
120
120
  stream.graph.addOperator(operator)
121
- stream.graph.addStream(output.connectReader())
122
121
  return output
123
122
  }
124
123
  }
@@ -45,7 +45,6 @@ export function tap<T>(f: (data: MultiSet<T>) => void): PipedOperator<T, T> {
45
45
  f
46
46
  )
47
47
  stream.graph.addOperator(operator)
48
- stream.graph.addStream(output.connectReader())
49
48
  return output
50
49
  }
51
50
  }
@@ -327,7 +327,6 @@ export function topKWithFractionalIndex<KType, T>(
327
327
  opts
328
328
  )
329
329
  stream.graph.addOperator(operator)
330
- stream.graph.addStream(output.connectReader())
331
330
  return output
332
331
  }
333
332
  }
@@ -302,7 +302,6 @@ export function topKWithFractionalIndexBTree<KType, T>(
302
302
  opts
303
303
  )
304
304
  stream.graph.addOperator(operator)
305
- stream.graph.addStream(output.connectReader())
306
305
  return output
307
306
  }
308
307
  }
package/src/types.ts CHANGED
@@ -27,7 +27,6 @@ export interface ID2 {
27
27
  getNextOperatorId: () => number
28
28
  newInput: <T>() => IStreamBuilder<T>
29
29
  addOperator: (operator: UnaryOperator<any> | BinaryOperator<any>) => void
30
- addStream: (stream: DifferenceStreamReader<any>) => void
31
30
  finalize: () => void
32
31
  step: () => void
33
32
  }
@@ -1,83 +0,0 @@
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 _inner;
10
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
11
- const utils = require("./utils.cjs");
12
- const hash = require("./hashing/hash.cjs");
13
- class HashIndex {
14
- constructor() {
15
- __privateAdd(this, _inner);
16
- __privateSet(this, _inner, new utils.DefaultMap(
17
- () => new utils.DefaultMap(() => [void 0, 0])
18
- ));
19
- }
20
- toString(indent = false) {
21
- return `HashIndex(${JSON.stringify(
22
- [...__privateGet(this, _inner)].map(([k, valueMap]) => [k, [...valueMap]]),
23
- void 0,
24
- indent ? 2 : void 0
25
- )})`;
26
- }
27
- get(key) {
28
- const valueMap = __privateGet(this, _inner).get(key);
29
- return [...valueMap.values()];
30
- }
31
- getMultiplicity(key, value) {
32
- const valueMap = __privateGet(this, _inner).get(key);
33
- const valueHash = hash.hash(value);
34
- const [, multiplicity] = valueMap.get(valueHash);
35
- return multiplicity;
36
- }
37
- entries() {
38
- return __privateGet(this, _inner).entries();
39
- }
40
- *entriesIterator() {
41
- for (const [key, valueMap] of __privateGet(this, _inner).entries()) {
42
- for (const [_valueHash, [value, multiplicity]] of valueMap.entries()) {
43
- yield [key, [value, multiplicity]];
44
- }
45
- }
46
- }
47
- has(key) {
48
- return __privateGet(this, _inner).has(key);
49
- }
50
- delete(key) {
51
- __privateGet(this, _inner).delete(key);
52
- }
53
- get size() {
54
- return __privateGet(this, _inner).size;
55
- }
56
- /**
57
- * Adds a value to the index and does not return anything
58
- * except if the addition caused the value to be removed
59
- * and the key to be left with only a single value.
60
- * In that case, we return the single remaining value.
61
- */
62
- addValue(key, value) {
63
- const [val, multiplicity] = value;
64
- const valueMap = __privateGet(this, _inner).get(key);
65
- const valueHash = hash.hash(val);
66
- const [, existingMultiplicity] = valueMap.get(valueHash);
67
- const newMultiplicity = existingMultiplicity + multiplicity;
68
- if (multiplicity !== 0) {
69
- if (newMultiplicity === 0) {
70
- valueMap.delete(valueHash);
71
- if (valueMap.size === 1) {
72
- return valueMap.entries().next().value[1];
73
- }
74
- } else {
75
- valueMap.set(valueHash, [val, newMultiplicity]);
76
- }
77
- }
78
- __privateGet(this, _inner).set(key, valueMap);
79
- }
80
- }
81
- _inner = new WeakMap();
82
- exports.HashIndex = HashIndex;
83
- //# sourceMappingURL=hashIndex.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hashIndex.cjs","sources":["../../src/hashIndex.ts"],"sourcesContent":["import { DefaultMap } from \"./utils.js\"\nimport { hash } from \"./hashing/index.js\"\nimport type { Hash } from \"./hashing/index.js\"\n\n/**\n * A map from a difference collection trace's keys -> (value, multiplicities) that changed.\n * Used in operations like join and reduce where the operation needs to\n * exploit the key-value structure of the data to run efficiently.\n */\nexport class HashIndex<K, V> {\n #inner: DefaultMap<K, DefaultMap<Hash, [V, number]>>\n\n constructor() {\n this.#inner = new DefaultMap<K, DefaultMap<Hash, [V, number]>>(\n () => new DefaultMap<Hash, [V, number]>(() => [undefined as any as V, 0])\n )\n // #inner is as map of:\n // {\n // [key]: {\n // [hash(value)]: [value, multiplicity]\n // }\n // }\n }\n\n toString(indent = false): string {\n return `HashIndex(${JSON.stringify(\n [...this.#inner].map(([k, valueMap]) => [k, [...valueMap]]),\n undefined,\n indent ? 2 : undefined\n )})`\n }\n\n get(key: K): Array<[V, number]> {\n const valueMap = this.#inner.get(key)\n return [...valueMap.values()]\n }\n\n getMultiplicity(key: K, value: V): number {\n const valueMap = this.#inner.get(key)\n const valueHash = hash(value)\n const [, multiplicity] = valueMap.get(valueHash)\n return multiplicity\n }\n\n entries() {\n return this.#inner.entries()\n }\n\n *entriesIterator(): Generator<[K, [V, number]]> {\n for (const [key, valueMap] of this.#inner.entries()) {\n for (const [_valueHash, [value, multiplicity]] of valueMap.entries()) {\n yield [key, [value, multiplicity]]\n }\n }\n }\n\n has(key: K): boolean {\n return this.#inner.has(key)\n }\n\n delete(key: K): void {\n this.#inner.delete(key)\n }\n\n get size(): number {\n return this.#inner.size\n }\n\n /**\n * Adds a value to the index and does not return anything\n * except if the addition caused the value to be removed\n * and the key to be left with only a single value.\n * In that case, we return the single remaining value.\n */\n addValue(key: K, value: [V, number]): [V, number] | void {\n const [val, multiplicity] = value\n const valueMap = this.#inner.get(key)\n const valueHash = hash(val)\n const [, existingMultiplicity] = valueMap.get(valueHash)\n const newMultiplicity = existingMultiplicity + multiplicity\n if (multiplicity !== 0) {\n if (newMultiplicity === 0) {\n valueMap.delete(valueHash)\n if (valueMap.size === 1) {\n // Signal that the key only has a single remaining value\n return valueMap.entries().next().value![1]\n }\n } else {\n valueMap.set(valueHash, [val, newMultiplicity])\n }\n }\n this.#inner.set(key, valueMap)\n }\n}\n"],"names":["DefaultMap","hash"],"mappings":";;;;;;;;;;;;AASO,MAAM,UAAgB;AAAA,EAG3B,cAAc;AAFd;AAGE,uBAAK,QAAS,IAAIA,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AACvD,UAAM,CAAC,KAAK,YAAY,IAAI;AAC5B,UAAM,WAAW,mBAAK,QAAO,IAAI,GAAG;AACpC,UAAM,YAAYA,KAAAA,KAAK,GAAG;AAC1B,UAAM,CAAA,EAAG,oBAAoB,IAAI,SAAS,IAAI,SAAS;AACvD,UAAM,kBAAkB,uBAAuB;AAC/C,QAAI,iBAAiB,GAAG;AACtB,UAAI,oBAAoB,GAAG;AACzB,iBAAS,OAAO,SAAS;AACzB,YAAI,SAAS,SAAS,GAAG;AAEvB,iBAAO,SAAS,QAAA,EAAU,KAAA,EAAO,MAAO,CAAC;AAAA,QAC3C;AAAA,MACF,OAAO;AACL,iBAAS,IAAI,WAAW,CAAC,KAAK,eAAe,CAAC;AAAA,MAChD;AAAA,IACF;AACA,uBAAK,QAAO,IAAI,KAAK,QAAQ;AAAA,EAC/B;AACF;AAnFE;;"}
@@ -1,25 +0,0 @@
1
- import { DefaultMap } from './utils.js';
2
- /**
3
- * A map from a difference collection trace's keys -> (value, multiplicities) that changed.
4
- * Used in operations like join and reduce where the operation needs to
5
- * exploit the key-value structure of the data to run efficiently.
6
- */
7
- export declare class HashIndex<K, V> {
8
- #private;
9
- constructor();
10
- toString(indent?: boolean): string;
11
- get(key: K): Array<[V, number]>;
12
- getMultiplicity(key: K, value: V): number;
13
- entries(): MapIterator<[K, DefaultMap<number, [V, number]>]>;
14
- entriesIterator(): Generator<[K, [V, number]]>;
15
- has(key: K): boolean;
16
- delete(key: K): void;
17
- get size(): number;
18
- /**
19
- * Adds a value to the index and does not return anything
20
- * except if the addition caused the value to be removed
21
- * and the key to be left with only a single value.
22
- * In that case, we return the single remaining value.
23
- */
24
- addValue(key: K, value: [V, number]): [V, number] | void;
25
- }
@@ -1,74 +0,0 @@
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, _ValueIndex_instances, setMultiplicity_fn;
11
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
12
- const hash = require("./hashing/hash.cjs");
13
- class ValueIndex {
14
- // Maps key to the value and its multiplicity
15
- constructor() {
16
- __privateAdd(this, _ValueIndex_instances);
17
- __privateAdd(this, _inner);
18
- __privateSet(this, _inner, /* @__PURE__ */ new Map());
19
- }
20
- toString(indent = false) {
21
- return `ValueIndex(${JSON.stringify(
22
- [...__privateGet(this, _inner).entries()],
23
- void 0,
24
- indent ? 2 : void 0
25
- )})`;
26
- }
27
- get(key) {
28
- return __privateGet(this, _inner).get(key);
29
- }
30
- getMultiplicity(key) {
31
- var _a;
32
- return ((_a = this.get(key)) == null ? void 0 : _a[1]) ?? 0;
33
- }
34
- entries() {
35
- return __privateGet(this, _inner).entries();
36
- }
37
- has(key) {
38
- return __privateGet(this, _inner).has(key);
39
- }
40
- delete(key) {
41
- __privateGet(this, _inner).delete(key);
42
- }
43
- get size() {
44
- return __privateGet(this, _inner).size;
45
- }
46
- addValue(key, v) {
47
- const [value, multiplicity] = v;
48
- if (multiplicity === 0) {
49
- return;
50
- }
51
- if (this.has(key)) {
52
- const [currValue, currMultiplicity] = this.get(key);
53
- if (hash.hash(value) === hash.hash(currValue)) {
54
- __privateMethod(this, _ValueIndex_instances, setMultiplicity_fn).call(this, key, value, currMultiplicity + multiplicity);
55
- return;
56
- }
57
- throw new Error(
58
- `Cannot add value for key ${key} because it already exists in ValueIndex with a different value`
59
- );
60
- }
61
- __privateGet(this, _inner).set(key, [value, multiplicity]);
62
- }
63
- }
64
- _inner = new WeakMap();
65
- _ValueIndex_instances = new WeakSet();
66
- setMultiplicity_fn = function(key, value, multiplicity) {
67
- if (multiplicity === 0) {
68
- __privateGet(this, _inner).delete(key);
69
- } else {
70
- __privateGet(this, _inner).set(key, [value, multiplicity]);
71
- }
72
- };
73
- exports.ValueIndex = ValueIndex;
74
- //# sourceMappingURL=valueIndex.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"valueIndex.cjs","sources":["../../src/valueIndex.ts"],"sourcesContent":["import { hash } from \"./hashing/index.js\"\n\n/**\n * A map from a difference collection trace's keys -> (value, multiplicities) that changed.\n * Used in operations like join and reduce where the operation needs to\n * exploit the key-value structure of the data to run efficiently.\n */\nexport class ValueIndex<K, V> {\n #inner: Map<K, [V, number]> // Maps key to the value and its multiplicity\n\n constructor() {\n this.#inner = new Map()\n }\n\n toString(indent = false): string {\n return `ValueIndex(${JSON.stringify(\n [...this.#inner.entries()],\n undefined,\n indent ? 2 : undefined\n )})`\n }\n\n get(key: K): [V, number] | undefined {\n return this.#inner.get(key)\n }\n\n getMultiplicity(key: K): number {\n return this.get(key)?.[1] ?? 0\n }\n\n entries() {\n return this.#inner.entries()\n }\n\n has(key: K): boolean {\n return this.#inner.has(key)\n }\n\n delete(key: K): void {\n this.#inner.delete(key)\n }\n\n get size(): number {\n return this.#inner.size\n }\n\n addValue(key: K, v: [V, number]): void {\n const [value, multiplicity] = v\n\n if (multiplicity === 0) {\n return\n }\n\n if (this.has(key)) {\n const [currValue, currMultiplicity] = this.get(key)!\n if (hash(value) === hash(currValue)) {\n // Update the multiplicity\n this.#setMultiplicity(key, value, currMultiplicity + multiplicity)\n return\n }\n // Different value, not allowed.\n // ValueIndex only supports one value per key.\n throw new Error(\n `Cannot add value for key ${key} because it already exists in ValueIndex with a different value`\n )\n }\n\n this.#inner.set(key, [value, multiplicity])\n }\n\n #setMultiplicity(key: K, value: V, multiplicity: number): void {\n if (multiplicity === 0) {\n this.#inner.delete(key)\n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EAC5C;AASF;AArEE;AADK;AA+DL,qBAAA,SAAiB,KAAQ,OAAU,cAA4B;AAC7D,MAAI,iBAAiB,GAAG;AACtB,uBAAK,QAAO,OAAO,GAAG;AAAA,EACxB,OAAO;AACL,uBAAK,QAAO,IAAI,KAAK,CAAC,OAAO,YAAY,CAAC;AAAA,EAC5C;AACF;;"}
@@ -1,17 +0,0 @@
1
- /**
2
- * A map from a difference collection trace's keys -> (value, multiplicities) that changed.
3
- * Used in operations like join and reduce where the operation needs to
4
- * exploit the key-value structure of the data to run efficiently.
5
- */
6
- export declare class ValueIndex<K, V> {
7
- #private;
8
- constructor();
9
- toString(indent?: boolean): string;
10
- get(key: K): [V, number] | undefined;
11
- getMultiplicity(key: K): number;
12
- entries(): MapIterator<[K, [V, number]]>;
13
- has(key: K): boolean;
14
- delete(key: K): void;
15
- get size(): number;
16
- addValue(key: K, v: [V, number]): void;
17
- }
@@ -1,25 +0,0 @@
1
- import { DefaultMap } from './utils.js';
2
- /**
3
- * A map from a difference collection trace's keys -> (value, multiplicities) that changed.
4
- * Used in operations like join and reduce where the operation needs to
5
- * exploit the key-value structure of the data to run efficiently.
6
- */
7
- export declare class HashIndex<K, V> {
8
- #private;
9
- constructor();
10
- toString(indent?: boolean): string;
11
- get(key: K): Array<[V, number]>;
12
- getMultiplicity(key: K, value: V): number;
13
- entries(): MapIterator<[K, DefaultMap<number, [V, number]>]>;
14
- entriesIterator(): Generator<[K, [V, number]]>;
15
- has(key: K): boolean;
16
- delete(key: K): void;
17
- get size(): number;
18
- /**
19
- * Adds a value to the index and does not return anything
20
- * except if the addition caused the value to be removed
21
- * and the key to be left with only a single value.
22
- * In that case, we return the single remaining value.
23
- */
24
- addValue(key: K, value: [V, number]): [V, number] | void;
25
- }
@@ -1,83 +0,0 @@
1
- var __typeError = (msg) => {
2
- throw TypeError(msg);
3
- };
4
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
- var _inner;
9
- import { DefaultMap } from "./utils.js";
10
- import { hash } from "./hashing/hash.js";
11
- class HashIndex {
12
- constructor() {
13
- __privateAdd(this, _inner);
14
- __privateSet(this, _inner, new DefaultMap(
15
- () => new DefaultMap(() => [void 0, 0])
16
- ));
17
- }
18
- toString(indent = false) {
19
- return `HashIndex(${JSON.stringify(
20
- [...__privateGet(this, _inner)].map(([k, valueMap]) => [k, [...valueMap]]),
21
- void 0,
22
- indent ? 2 : void 0
23
- )})`;
24
- }
25
- get(key) {
26
- const valueMap = __privateGet(this, _inner).get(key);
27
- return [...valueMap.values()];
28
- }
29
- getMultiplicity(key, value) {
30
- const valueMap = __privateGet(this, _inner).get(key);
31
- const valueHash = hash(value);
32
- const [, multiplicity] = valueMap.get(valueHash);
33
- return multiplicity;
34
- }
35
- entries() {
36
- return __privateGet(this, _inner).entries();
37
- }
38
- *entriesIterator() {
39
- for (const [key, valueMap] of __privateGet(this, _inner).entries()) {
40
- for (const [_valueHash, [value, multiplicity]] of valueMap.entries()) {
41
- yield [key, [value, multiplicity]];
42
- }
43
- }
44
- }
45
- has(key) {
46
- return __privateGet(this, _inner).has(key);
47
- }
48
- delete(key) {
49
- __privateGet(this, _inner).delete(key);
50
- }
51
- get size() {
52
- return __privateGet(this, _inner).size;
53
- }
54
- /**
55
- * Adds a value to the index and does not return anything
56
- * except if the addition caused the value to be removed
57
- * and the key to be left with only a single value.
58
- * In that case, we return the single remaining value.
59
- */
60
- addValue(key, value) {
61
- const [val, multiplicity] = value;
62
- const valueMap = __privateGet(this, _inner).get(key);
63
- const valueHash = hash(val);
64
- const [, existingMultiplicity] = valueMap.get(valueHash);
65
- const newMultiplicity = existingMultiplicity + multiplicity;
66
- if (multiplicity !== 0) {
67
- if (newMultiplicity === 0) {
68
- valueMap.delete(valueHash);
69
- if (valueMap.size === 1) {
70
- return valueMap.entries().next().value[1];
71
- }
72
- } else {
73
- valueMap.set(valueHash, [val, newMultiplicity]);
74
- }
75
- }
76
- __privateGet(this, _inner).set(key, valueMap);
77
- }
78
- }
79
- _inner = new WeakMap();
80
- export {
81
- HashIndex
82
- };
83
- //# sourceMappingURL=hashIndex.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hashIndex.js","sources":["../../src/hashIndex.ts"],"sourcesContent":["import { DefaultMap } from \"./utils.js\"\nimport { hash } from \"./hashing/index.js\"\nimport type { Hash } from \"./hashing/index.js\"\n\n/**\n * A map from a difference collection trace's keys -> (value, multiplicities) that changed.\n * Used in operations like join and reduce where the operation needs to\n * exploit the key-value structure of the data to run efficiently.\n */\nexport class HashIndex<K, V> {\n #inner: DefaultMap<K, DefaultMap<Hash, [V, number]>>\n\n constructor() {\n this.#inner = new DefaultMap<K, DefaultMap<Hash, [V, number]>>(\n () => new DefaultMap<Hash, [V, number]>(() => [undefined as any as V, 0])\n )\n // #inner is as map of:\n // {\n // [key]: {\n // [hash(value)]: [value, multiplicity]\n // }\n // }\n }\n\n toString(indent = false): string {\n return `HashIndex(${JSON.stringify(\n [...this.#inner].map(([k, valueMap]) => [k, [...valueMap]]),\n undefined,\n indent ? 2 : undefined\n )})`\n }\n\n get(key: K): Array<[V, number]> {\n const valueMap = this.#inner.get(key)\n return [...valueMap.values()]\n }\n\n getMultiplicity(key: K, value: V): number {\n const valueMap = this.#inner.get(key)\n const valueHash = hash(value)\n const [, multiplicity] = valueMap.get(valueHash)\n return multiplicity\n }\n\n entries() {\n return this.#inner.entries()\n }\n\n *entriesIterator(): Generator<[K, [V, number]]> {\n for (const [key, valueMap] of this.#inner.entries()) {\n for (const [_valueHash, [value, multiplicity]] of valueMap.entries()) {\n yield [key, [value, multiplicity]]\n }\n }\n }\n\n has(key: K): boolean {\n return this.#inner.has(key)\n }\n\n delete(key: K): void {\n this.#inner.delete(key)\n }\n\n get size(): number {\n return this.#inner.size\n }\n\n /**\n * Adds a value to the index and does not return anything\n * except if the addition caused the value to be removed\n * and the key to be left with only a single value.\n * In that case, we return the single remaining value.\n */\n addValue(key: K, value: [V, number]): [V, number] | void {\n const [val, multiplicity] = value\n const valueMap = this.#inner.get(key)\n const valueHash = hash(val)\n const [, existingMultiplicity] = valueMap.get(valueHash)\n const newMultiplicity = existingMultiplicity + multiplicity\n if (multiplicity !== 0) {\n if (newMultiplicity === 0) {\n valueMap.delete(valueHash)\n if (valueMap.size === 1) {\n // Signal that the key only has a single remaining value\n return valueMap.entries().next().value![1]\n }\n } else {\n valueMap.set(valueHash, [val, newMultiplicity])\n }\n }\n this.#inner.set(key, valueMap)\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AASO,MAAM,UAAgB;AAAA,EAG3B,cAAc;AAFd;AAGE,uBAAK,QAAS,IAAI;AAAA,MAChB,MAAM,IAAI,WAA8B,MAAM,CAAC,QAAuB,CAAC,CAAC;AAAA,IAAA;AAAA,EAQ5E;AAAA,EAEA,SAAS,SAAS,OAAe;AAC/B,WAAO,aAAa,KAAK;AAAA,MACvB,CAAC,GAAG,mBAAK,OAAM,EAAE,IAAI,CAAC,CAAC,GAAG,QAAQ,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC;AAAA,MAC1D;AAAA,MACA,SAAS,IAAI;AAAA,IAAA,CACd;AAAA,EACH;AAAA,EAEA,IAAI,KAA4B;AAC9B,UAAM,WAAW,mBAAK,QAAO,IAAI,GAAG;AACpC,WAAO,CAAC,GAAG,SAAS,QAAQ;AAAA,EAC9B;AAAA,EAEA,gBAAgB,KAAQ,OAAkB;AACxC,UAAM,WAAW,mBAAK,QAAO,IAAI,GAAG;AACpC,UAAM,YAAY,KAAK,KAAK;AAC5B,UAAM,CAAA,EAAG,YAAY,IAAI,SAAS,IAAI,SAAS;AAC/C,WAAO;AAAA,EACT;AAAA,EAEA,UAAU;AACR,WAAO,mBAAK,QAAO,QAAA;AAAA,EACrB;AAAA,EAEA,CAAC,kBAA+C;AAC9C,eAAW,CAAC,KAAK,QAAQ,KAAK,mBAAK,QAAO,WAAW;AACnD,iBAAW,CAAC,YAAY,CAAC,OAAO,YAAY,CAAC,KAAK,SAAS,WAAW;AACpE,cAAM,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC;AAAA,MACnC;AAAA,IACF;AAAA,EACF;AAAA,EAEA,IAAI,KAAiB;AACnB,WAAO,mBAAK,QAAO,IAAI,GAAG;AAAA,EAC5B;AAAA,EAEA,OAAO,KAAc;AACnB,uBAAK,QAAO,OAAO,GAAG;AAAA,EACxB;AAAA,EAEA,IAAI,OAAe;AACjB,WAAO,mBAAK,QAAO;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,SAAS,KAAQ,OAAwC;AACvD,UAAM,CAAC,KAAK,YAAY,IAAI;AAC5B,UAAM,WAAW,mBAAK,QAAO,IAAI,GAAG;AACpC,UAAM,YAAY,KAAK,GAAG;AAC1B,UAAM,CAAA,EAAG,oBAAoB,IAAI,SAAS,IAAI,SAAS;AACvD,UAAM,kBAAkB,uBAAuB;AAC/C,QAAI,iBAAiB,GAAG;AACtB,UAAI,oBAAoB,GAAG;AACzB,iBAAS,OAAO,SAAS;AACzB,YAAI,SAAS,SAAS,GAAG;AAEvB,iBAAO,SAAS,QAAA,EAAU,KAAA,EAAO,MAAO,CAAC;AAAA,QAC3C;AAAA,MACF,OAAO;AACL,iBAAS,IAAI,WAAW,CAAC,KAAK,eAAe,CAAC;AAAA,MAChD;AAAA,IACF;AACA,uBAAK,QAAO,IAAI,KAAK,QAAQ;AAAA,EAC/B;AACF;AAnFE;"}
@@ -1,17 +0,0 @@
1
- /**
2
- * A map from a difference collection trace's keys -> (value, multiplicities) that changed.
3
- * Used in operations like join and reduce where the operation needs to
4
- * exploit the key-value structure of the data to run efficiently.
5
- */
6
- export declare class ValueIndex<K, V> {
7
- #private;
8
- constructor();
9
- toString(indent?: boolean): string;
10
- get(key: K): [V, number] | undefined;
11
- getMultiplicity(key: K): number;
12
- entries(): MapIterator<[K, [V, number]]>;
13
- has(key: K): boolean;
14
- delete(key: K): void;
15
- get size(): number;
16
- addValue(key: K, v: [V, number]): void;
17
- }
@@ -1,74 +0,0 @@
1
- var __typeError = (msg) => {
2
- throw TypeError(msg);
3
- };
4
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
9
- var _inner, _ValueIndex_instances, setMultiplicity_fn;
10
- import { hash } from "./hashing/hash.js";
11
- class ValueIndex {
12
- // Maps key to the value and its multiplicity
13
- constructor() {
14
- __privateAdd(this, _ValueIndex_instances);
15
- __privateAdd(this, _inner);
16
- __privateSet(this, _inner, /* @__PURE__ */ new Map());
17
- }
18
- toString(indent = false) {
19
- return `ValueIndex(${JSON.stringify(
20
- [...__privateGet(this, _inner).entries()],
21
- void 0,
22
- indent ? 2 : void 0
23
- )})`;
24
- }
25
- get(key) {
26
- return __privateGet(this, _inner).get(key);
27
- }
28
- getMultiplicity(key) {
29
- var _a;
30
- return ((_a = this.get(key)) == null ? void 0 : _a[1]) ?? 0;
31
- }
32
- entries() {
33
- return __privateGet(this, _inner).entries();
34
- }
35
- has(key) {
36
- return __privateGet(this, _inner).has(key);
37
- }
38
- delete(key) {
39
- __privateGet(this, _inner).delete(key);
40
- }
41
- get size() {
42
- return __privateGet(this, _inner).size;
43
- }
44
- addValue(key, v) {
45
- const [value, multiplicity] = v;
46
- if (multiplicity === 0) {
47
- return;
48
- }
49
- if (this.has(key)) {
50
- const [currValue, currMultiplicity] = this.get(key);
51
- if (hash(value) === hash(currValue)) {
52
- __privateMethod(this, _ValueIndex_instances, setMultiplicity_fn).call(this, key, value, currMultiplicity + multiplicity);
53
- return;
54
- }
55
- throw new Error(
56
- `Cannot add value for key ${key} because it already exists in ValueIndex with a different value`
57
- );
58
- }
59
- __privateGet(this, _inner).set(key, [value, multiplicity]);
60
- }
61
- }
62
- _inner = new WeakMap();
63
- _ValueIndex_instances = new WeakSet();
64
- setMultiplicity_fn = function(key, value, multiplicity) {
65
- if (multiplicity === 0) {
66
- __privateGet(this, _inner).delete(key);
67
- } else {
68
- __privateGet(this, _inner).set(key, [value, multiplicity]);
69
- }
70
- };
71
- export {
72
- ValueIndex
73
- };
74
- //# sourceMappingURL=valueIndex.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"valueIndex.js","sources":["../../src/valueIndex.ts"],"sourcesContent":["import { hash } from \"./hashing/index.js\"\n\n/**\n * A map from a difference collection trace's keys -> (value, multiplicities) that changed.\n * Used in operations like join and reduce where the operation needs to\n * exploit the key-value structure of the data to run efficiently.\n */\nexport class ValueIndex<K, V> {\n #inner: Map<K, [V, number]> // Maps key to the value and its multiplicity\n\n constructor() {\n this.#inner = new Map()\n }\n\n toString(indent = false): string {\n return `ValueIndex(${JSON.stringify(\n [...this.#inner.entries()],\n undefined,\n indent ? 2 : undefined\n )})`\n }\n\n get(key: K): [V, number] | undefined {\n return this.#inner.get(key)\n }\n\n getMultiplicity(key: K): number {\n return this.get(key)?.[1] ?? 0\n }\n\n entries() {\n return this.#inner.entries()\n }\n\n has(key: K): boolean {\n return this.#inner.has(key)\n }\n\n delete(key: K): void {\n this.#inner.delete(key)\n }\n\n get size(): number {\n return this.#inner.size\n }\n\n addValue(key: K, v: [V, number]): void {\n const [value, multiplicity] = v\n\n if (multiplicity === 0) {\n return\n }\n\n if (this.has(key)) {\n const [currValue, currMultiplicity] = this.get(key)!\n if (hash(value) === hash(currValue)) {\n // Update the multiplicity\n this.#setMultiplicity(key, value, currMultiplicity + multiplicity)\n return\n }\n // Different value, not allowed.\n // ValueIndex only supports one value per key.\n throw new Error(\n `Cannot add value for key ${key} because it already exists in ValueIndex with a different value`\n )\n }\n\n this.#inner.set(key, [value, multiplicity])\n }\n\n #setMultiplicity(key: K, value: V, multiplicity: number): void {\n if (multiplicity === 0) {\n this.#inner.delete(key)\n } else {\n this.#inner.set(key, [value, multiplicity])\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAOO,MAAM,WAAiB;AAAA;AAAA,EAG5B,cAAc;AAHT;AACL;AAGE,uBAAK,4BAAa,IAAA;AAAA,EACpB;AAAA,EAEA,SAAS,SAAS,OAAe;AAC/B,WAAO,cAAc,KAAK;AAAA,MACxB,CAAC,GAAG,mBAAK,QAAO,SAAS;AAAA,MACzB;AAAA,MACA,SAAS,IAAI;AAAA,IAAA,CACd;AAAA,EACH;AAAA,EAEA,IAAI,KAAiC;AACnC,WAAO,mBAAK,QAAO,IAAI,GAAG;AAAA,EAC5B;AAAA,EAEA,gBAAgB,KAAgB;;AAC9B,aAAO,UAAK,IAAI,GAAG,MAAZ,mBAAgB,OAAM;AAAA,EAC/B;AAAA,EAEA,UAAU;AACR,WAAO,mBAAK,QAAO,QAAA;AAAA,EACrB;AAAA,EAEA,IAAI,KAAiB;AACnB,WAAO,mBAAK,QAAO,IAAI,GAAG;AAAA,EAC5B;AAAA,EAEA,OAAO,KAAc;AACnB,uBAAK,QAAO,OAAO,GAAG;AAAA,EACxB;AAAA,EAEA,IAAI,OAAe;AACjB,WAAO,mBAAK,QAAO;AAAA,EACrB;AAAA,EAEA,SAAS,KAAQ,GAAsB;AACrC,UAAM,CAAC,OAAO,YAAY,IAAI;AAE9B,QAAI,iBAAiB,GAAG;AACtB;AAAA,IACF;AAEA,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