* 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)
| 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 | /** |