@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.
- package/dist/cjs/d2.cjs +1 -8
- package/dist/cjs/d2.cjs.map +1 -1
- package/dist/cjs/d2.d.cts +0 -1
- package/dist/cjs/indexes.cjs +243 -85
- package/dist/cjs/indexes.cjs.map +1 -1
- package/dist/cjs/indexes.d.cts +58 -7
- package/dist/cjs/operators/concat.cjs +0 -1
- package/dist/cjs/operators/concat.cjs.map +1 -1
- package/dist/cjs/operators/consolidate.cjs +0 -1
- package/dist/cjs/operators/consolidate.cjs.map +1 -1
- package/dist/cjs/operators/count.cjs +0 -1
- package/dist/cjs/operators/count.cjs.map +1 -1
- package/dist/cjs/operators/debug.cjs +0 -1
- package/dist/cjs/operators/debug.cjs.map +1 -1
- package/dist/cjs/operators/distinct.cjs +2 -3
- package/dist/cjs/operators/distinct.cjs.map +1 -1
- package/dist/cjs/operators/distinct.d.cts +6 -4
- package/dist/cjs/operators/filter.cjs +0 -1
- package/dist/cjs/operators/filter.cjs.map +1 -1
- package/dist/cjs/operators/join.cjs +0 -1
- package/dist/cjs/operators/join.cjs.map +1 -1
- package/dist/cjs/operators/map.cjs +0 -1
- package/dist/cjs/operators/map.cjs.map +1 -1
- package/dist/cjs/operators/negate.cjs +0 -1
- package/dist/cjs/operators/negate.cjs.map +1 -1
- package/dist/cjs/operators/output.cjs +0 -1
- package/dist/cjs/operators/output.cjs.map +1 -1
- package/dist/cjs/operators/reduce.cjs +0 -1
- package/dist/cjs/operators/reduce.cjs.map +1 -1
- package/dist/cjs/operators/tap.cjs +0 -1
- package/dist/cjs/operators/tap.cjs.map +1 -1
- package/dist/cjs/operators/topKWithFractionalIndex.cjs +0 -1
- package/dist/cjs/operators/topKWithFractionalIndex.cjs.map +1 -1
- package/dist/cjs/types.d.cts +0 -1
- package/dist/cjs/utils.cjs +0 -12
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/esm/d2.d.ts +0 -1
- package/dist/esm/d2.js +1 -8
- package/dist/esm/d2.js.map +1 -1
- package/dist/esm/indexes.d.ts +58 -7
- package/dist/esm/indexes.js +243 -85
- package/dist/esm/indexes.js.map +1 -1
- package/dist/esm/operators/concat.js +0 -1
- package/dist/esm/operators/concat.js.map +1 -1
- package/dist/esm/operators/consolidate.js +0 -1
- package/dist/esm/operators/consolidate.js.map +1 -1
- package/dist/esm/operators/count.js +0 -1
- package/dist/esm/operators/count.js.map +1 -1
- package/dist/esm/operators/debug.js +0 -1
- package/dist/esm/operators/debug.js.map +1 -1
- package/dist/esm/operators/distinct.d.ts +6 -4
- package/dist/esm/operators/distinct.js +2 -3
- package/dist/esm/operators/distinct.js.map +1 -1
- package/dist/esm/operators/filter.js +0 -1
- package/dist/esm/operators/filter.js.map +1 -1
- package/dist/esm/operators/join.js +0 -1
- package/dist/esm/operators/join.js.map +1 -1
- package/dist/esm/operators/map.js +0 -1
- package/dist/esm/operators/map.js.map +1 -1
- package/dist/esm/operators/negate.js +0 -1
- package/dist/esm/operators/negate.js.map +1 -1
- package/dist/esm/operators/output.js +0 -1
- package/dist/esm/operators/output.js.map +1 -1
- package/dist/esm/operators/reduce.js +0 -1
- package/dist/esm/operators/reduce.js.map +1 -1
- package/dist/esm/operators/tap.js +0 -1
- package/dist/esm/operators/tap.js.map +1 -1
- package/dist/esm/operators/topKWithFractionalIndex.js +0 -1
- package/dist/esm/operators/topKWithFractionalIndex.js.map +1 -1
- package/dist/esm/types.d.ts +0 -1
- package/dist/esm/utils.js +1 -13
- package/dist/esm/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/d2.ts +0 -7
- package/src/indexes.ts +365 -90
- package/src/operators/concat.ts +0 -1
- package/src/operators/consolidate.ts +0 -1
- package/src/operators/count.ts +0 -1
- package/src/operators/debug.ts +0 -1
- package/src/operators/distinct.ts +13 -9
- package/src/operators/filter.ts +0 -1
- package/src/operators/join.ts +0 -1
- package/src/operators/map.ts +0 -1
- package/src/operators/negate.ts +0 -1
- package/src/operators/output.ts +0 -1
- package/src/operators/reduce.ts +0 -1
- package/src/operators/tap.ts +0 -1
- package/src/operators/topKWithFractionalIndex.ts +0 -1
- package/src/operators/topKWithFractionalIndexBTree.ts +0 -1
- package/src/types.ts +0 -1
- package/dist/cjs/hashIndex.cjs +0 -83
- package/dist/cjs/hashIndex.cjs.map +0 -1
- package/dist/cjs/hashIndex.d.cts +0 -25
- package/dist/cjs/valueIndex.cjs +0 -74
- package/dist/cjs/valueIndex.cjs.map +0 -1
- package/dist/cjs/valueIndex.d.cts +0 -17
- package/dist/esm/hashIndex.d.ts +0 -25
- package/dist/esm/hashIndex.js +0 -83
- package/dist/esm/hashIndex.js.map +0 -1
- package/dist/esm/valueIndex.d.ts +0 -17
- package/dist/esm/valueIndex.js +0 -74
- package/dist/esm/valueIndex.js.map +0 -1
- package/src/hashIndex.ts +0 -94
- package/src/valueIndex.ts +0 -78
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
|
-
}
|