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

Method addValue

packages/db-ivm/src/indexes.ts:114–133  ·  view source on GitHub ↗

* Add a value to the ValueMap. Returns true if the map becomes empty after the operation. * @param value - The full value to store * @param multiplicity - The multiplicity to add * @param hashKey - Optional hash key to use instead of hashing the full value (used when in PrefixMap context)

(value: TValue, multiplicity: number)

Source from the content-addressed store, hash-verified

112 * @param hashKey - Optional hash key to use instead of hashing the full value (used when in PrefixMap context)
113 */
114 addValue(value: TValue, multiplicity: number): boolean {
115 if (multiplicity === 0) return this.size === 0
116
117 const key = hash(value)
118 const currentValue = this.get(key)
119
120 if (currentValue) {
121 const [, currentMultiplicity] = currentValue
122 const newMultiplicity = currentMultiplicity + multiplicity
123 if (newMultiplicity === 0) {
124 this.delete(key)
125 } else {
126 this.set(key, [value, newMultiplicity])
127 }
128 } else {
129 this.set(key, [value, multiplicity])
130 }
131
132 return this.size === 0
133 }
134}
135
136/**

Callers

nothing calls this directly

Calls 4

hashFunction · 0.85
getMethod · 0.45
deleteMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected