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

Method processElement

packages/db-ivm/src/operators/topKState.ts:37–53  ·  view source on GitHub ↗

* Process an element update (insert or delete based on multiplicity change). * Returns the changes to the topK window.

(key: K, value: T, multiplicity: number)

Source from the content-addressed store, hash-verified

35 * Returns the changes to the topK window.
36 */
37 processElement(key: K, value: T, multiplicity: number): TopKChanges<[K, T]> {
38 const { oldMultiplicity, newMultiplicity } = this.#updateMultiplicity(
39 key,
40 multiplicity,
41 )
42
43 if (oldMultiplicity <= 0 && newMultiplicity > 0) {
44 // The value was invisible but should now be visible
45 return this.#topK.insert([key, value])
46 } else if (oldMultiplicity > 0 && newMultiplicity <= 0) {
47 // The value was visible but should now be invisible
48 return this.#topK.delete([key, value])
49 }
50 // The value was invisible and remains invisible,
51 // or was visible and remains visible - no topK change
52 return { moveIn: null, moveOut: null }
53 }
54
55 /**
56 * Move the topK window. Only works with TopKArray implementation.

Callers 1

#processElementMethod · 0.45

Calls 3

#updateMultiplicityMethod · 0.95
insertMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected