* Process an element update (insert or delete based on multiplicity change). * Returns the changes to the topK window.
(key: K, value: T, multiplicity: number)
| 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. |
no test coverage detected