MCPcopy Create free account
hub / github.com/TanStack/db / consolidate

Method consolidate

packages/db-ivm/src/multiset.ts:73–84  ·  view source on GitHub ↗

* Produce as output a collection that is logically equivalent to the input * but which combines identical instances of the same record into one * (record, multiplicity) pair.

()

Source from the content-addressed store, hash-verified

71 * (record, multiplicity) pair.
72 */
73 consolidate(): MultiSet<T> {
74 // Check if this looks like a keyed multiset (first item is a tuple of length 2)
75 if (this.#inner.length > 0) {
76 const firstItem = this.#inner[0]?.[0]
77 if (Array.isArray(firstItem) && firstItem.length === 2) {
78 return this.#consolidateKeyed()
79 }
80 }
81
82 // Fall back to original method for unkeyed data
83 return this.#consolidateUnkeyed()
84 }
85
86 /**
87 * Private method for consolidating keyed multisets where keys are strings/numbers

Callers 5

runMethod · 0.95
materializeResultsFunction · 0.95
topKFunction · 0.80
topKWithIndexFunction · 0.80
multiset.test.tsFile · 0.80

Calls 2

#consolidateKeyedMethod · 0.95
#consolidateUnkeyedMethod · 0.95

Tested by

no test coverage detected