@tanstack/db-ivm 0.1.7 → 0.1.9

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 (40) hide show
  1. package/dist/cjs/indexes.cjs +243 -85
  2. package/dist/cjs/indexes.cjs.map +1 -1
  3. package/dist/cjs/indexes.d.cts +58 -7
  4. package/dist/cjs/operators/distinct.cjs +2 -2
  5. package/dist/cjs/operators/distinct.cjs.map +1 -1
  6. package/dist/cjs/operators/distinct.d.cts +6 -4
  7. package/dist/cjs/operators/groupBy.cjs +12 -10
  8. package/dist/cjs/operators/groupBy.cjs.map +1 -1
  9. package/dist/cjs/operators/groupBy.d.cts +7 -4
  10. package/dist/cjs/utils.cjs +0 -12
  11. package/dist/cjs/utils.cjs.map +1 -1
  12. package/dist/esm/indexes.d.ts +58 -7
  13. package/dist/esm/indexes.js +243 -85
  14. package/dist/esm/indexes.js.map +1 -1
  15. package/dist/esm/operators/distinct.d.ts +6 -4
  16. package/dist/esm/operators/distinct.js +2 -2
  17. package/dist/esm/operators/distinct.js.map +1 -1
  18. package/dist/esm/operators/groupBy.d.ts +7 -4
  19. package/dist/esm/operators/groupBy.js +12 -10
  20. package/dist/esm/operators/groupBy.js.map +1 -1
  21. package/dist/esm/utils.js +1 -13
  22. package/dist/esm/utils.js.map +1 -1
  23. package/package.json +1 -1
  24. package/src/indexes.ts +365 -90
  25. package/src/operators/distinct.ts +13 -8
  26. package/src/operators/groupBy.ts +38 -18
  27. package/dist/cjs/hashIndex.cjs +0 -83
  28. package/dist/cjs/hashIndex.cjs.map +0 -1
  29. package/dist/cjs/hashIndex.d.cts +0 -25
  30. package/dist/cjs/valueIndex.cjs +0 -74
  31. package/dist/cjs/valueIndex.cjs.map +0 -1
  32. package/dist/cjs/valueIndex.d.cts +0 -17
  33. package/dist/esm/hashIndex.d.ts +0 -25
  34. package/dist/esm/hashIndex.js +0 -83
  35. package/dist/esm/hashIndex.js.map +0 -1
  36. package/dist/esm/valueIndex.d.ts +0 -17
  37. package/dist/esm/valueIndex.js +0 -74
  38. package/dist/esm/valueIndex.js.map +0 -1
  39. package/src/hashIndex.ts +0 -94
  40. package/src/valueIndex.ts +0 -78
@@ -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,MAAAA;AAAAA,MAChB,MAAM,IAAIA,MAAAA,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,MAA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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 } else {\n this.#inner.set(key, [value, multiplicity])\n }\n }\n}\n"],"names":["hash"],"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,CAA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
- /**
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,QAAI,KAAK,IAAI,GAAG,GAAG;AACjB,YAAM,CAAC,WAAW,gBAAgB,IAAI,KAAK,IAAI,GAAG;AAClD,UAAI,KAAK,KAAK,MAAM,KAAK,SAAS,GAAG;AAEnC,8BAAK,2CAAL,WAAsB,KAAK,OAAO,mBAAmB;AACrD;AAAA,MACF;AAGA,YAAM,IAAI;AAAA,QACR,4BAA4B,GAAG;AAAA,MAAA;AAAA,IAEnC;AAEA,uBAAK,QAAO,IAAI,KAAK,CAAC,OAAO,YAAY,CAAC;AAAA,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;"}
package/src/hashIndex.ts DELETED
@@ -1,94 +0,0 @@
1
- import { DefaultMap } from "./utils.js"
2
- import { hash } from "./hashing/index.js"
3
- import type { Hash } from "./hashing/index.js"
4
-
5
- /**
6
- * A map from a difference collection trace's keys -> (value, multiplicities) that changed.
7
- * Used in operations like join and reduce where the operation needs to
8
- * exploit the key-value structure of the data to run efficiently.
9
- */
10
- export class HashIndex<K, V> {
11
- #inner: DefaultMap<K, DefaultMap<Hash, [V, number]>>
12
-
13
- constructor() {
14
- this.#inner = new DefaultMap<K, DefaultMap<Hash, [V, number]>>(
15
- () => new DefaultMap<Hash, [V, number]>(() => [undefined as any as V, 0])
16
- )
17
- // #inner is as map of:
18
- // {
19
- // [key]: {
20
- // [hash(value)]: [value, multiplicity]
21
- // }
22
- // }
23
- }
24
-
25
- toString(indent = false): string {
26
- return `HashIndex(${JSON.stringify(
27
- [...this.#inner].map(([k, valueMap]) => [k, [...valueMap]]),
28
- undefined,
29
- indent ? 2 : undefined
30
- )})`
31
- }
32
-
33
- get(key: K): Array<[V, number]> {
34
- const valueMap = this.#inner.get(key)
35
- return [...valueMap.values()]
36
- }
37
-
38
- getMultiplicity(key: K, value: V): number {
39
- const valueMap = this.#inner.get(key)
40
- const valueHash = hash(value)
41
- const [, multiplicity] = valueMap.get(valueHash)
42
- return multiplicity
43
- }
44
-
45
- entries() {
46
- return this.#inner.entries()
47
- }
48
-
49
- *entriesIterator(): Generator<[K, [V, number]]> {
50
- for (const [key, valueMap] of this.#inner.entries()) {
51
- for (const [_valueHash, [value, multiplicity]] of valueMap.entries()) {
52
- yield [key, [value, multiplicity]]
53
- }
54
- }
55
- }
56
-
57
- has(key: K): boolean {
58
- return this.#inner.has(key)
59
- }
60
-
61
- delete(key: K): void {
62
- this.#inner.delete(key)
63
- }
64
-
65
- get size(): number {
66
- return this.#inner.size
67
- }
68
-
69
- /**
70
- * Adds a value to the index and does not return anything
71
- * except if the addition caused the value to be removed
72
- * and the key to be left with only a single value.
73
- * In that case, we return the single remaining value.
74
- */
75
- addValue(key: K, value: [V, number]): [V, number] | void {
76
- const [val, multiplicity] = value
77
- const valueMap = this.#inner.get(key)
78
- const valueHash = hash(val)
79
- const [, existingMultiplicity] = valueMap.get(valueHash)
80
- const newMultiplicity = existingMultiplicity + multiplicity
81
- if (multiplicity !== 0) {
82
- if (newMultiplicity === 0) {
83
- valueMap.delete(valueHash)
84
- if (valueMap.size === 1) {
85
- // Signal that the key only has a single remaining value
86
- return valueMap.entries().next().value![1]
87
- }
88
- } else {
89
- valueMap.set(valueHash, [val, newMultiplicity])
90
- }
91
- }
92
- this.#inner.set(key, valueMap)
93
- }
94
- }
package/src/valueIndex.ts DELETED
@@ -1,78 +0,0 @@
1
- import { hash } from "./hashing/index.js"
2
-
3
- /**
4
- * A map from a difference collection trace's keys -> (value, multiplicities) that changed.
5
- * Used in operations like join and reduce where the operation needs to
6
- * exploit the key-value structure of the data to run efficiently.
7
- */
8
- export class ValueIndex<K, V> {
9
- #inner: Map<K, [V, number]> // Maps key to the value and its multiplicity
10
-
11
- constructor() {
12
- this.#inner = new Map()
13
- }
14
-
15
- toString(indent = false): string {
16
- return `ValueIndex(${JSON.stringify(
17
- [...this.#inner.entries()],
18
- undefined,
19
- indent ? 2 : undefined
20
- )})`
21
- }
22
-
23
- get(key: K): [V, number] | undefined {
24
- return this.#inner.get(key)
25
- }
26
-
27
- getMultiplicity(key: K): number {
28
- return this.get(key)?.[1] ?? 0
29
- }
30
-
31
- entries() {
32
- return this.#inner.entries()
33
- }
34
-
35
- has(key: K): boolean {
36
- return this.#inner.has(key)
37
- }
38
-
39
- delete(key: K): void {
40
- this.#inner.delete(key)
41
- }
42
-
43
- get size(): number {
44
- return this.#inner.size
45
- }
46
-
47
- addValue(key: K, v: [V, number]): void {
48
- const [value, multiplicity] = v
49
-
50
- if (multiplicity === 0) {
51
- return
52
- }
53
-
54
- if (this.has(key)) {
55
- const [currValue, currMultiplicity] = this.get(key)!
56
- if (hash(value) === hash(currValue)) {
57
- // Update the multiplicity
58
- this.#setMultiplicity(key, value, currMultiplicity + multiplicity)
59
- return
60
- }
61
- // Different value, not allowed.
62
- // ValueIndex only supports one value per key.
63
- throw new Error(
64
- `Cannot add value for key ${key} because it already exists in ValueIndex with a different value`
65
- )
66
- }
67
-
68
- this.#inner.set(key, [value, multiplicity])
69
- }
70
-
71
- #setMultiplicity(key: K, value: V, multiplicity: number): void {
72
- if (multiplicity === 0) {
73
- this.#inner.delete(key)
74
- } else {
75
- this.#inner.set(key, [value, multiplicity])
76
- }
77
- }
78
- }