| 194 | } |
| 195 | |
| 196 | update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) { |
| 197 | const removed = value === NOT_SET; |
| 198 | |
| 199 | const entries = this.entries; |
| 200 | let idx = 0; |
| 201 | const len = entries.length; |
| 202 | for (; idx < len; idx++) { |
| 203 | if (is(key, entries[idx][0])) { |
| 204 | break; |
| 205 | } |
| 206 | } |
| 207 | const exists = idx < len; |
| 208 | |
| 209 | if (exists ? entries[idx][1] === value : removed) { |
| 210 | return this; |
| 211 | } |
| 212 | |
| 213 | SetRef(didAlter); |
| 214 | // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here |
| 215 | (removed || !exists) && SetRef(didChangeSize); |
| 216 | |
| 217 | if (removed && entries.length === 1) { |
| 218 | return; // undefined |
| 219 | } |
| 220 | |
| 221 | if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) { |
| 222 | return createNodes(ownerID, entries, key, value); |
| 223 | } |
| 224 | |
| 225 | const isEditable = ownerID && ownerID === this.ownerID; |
| 226 | const newEntries = isEditable ? entries : arrCopy(entries); |
| 227 | |
| 228 | if (exists) { |
| 229 | if (removed) { |
| 230 | // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here |
| 231 | idx === len - 1 |
| 232 | ? newEntries.pop() |
| 233 | : (newEntries[idx] = newEntries.pop()); |
| 234 | } else { |
| 235 | newEntries[idx] = [key, value]; |
| 236 | } |
| 237 | } else { |
| 238 | newEntries.push([key, value]); |
| 239 | } |
| 240 | |
| 241 | if (isEditable) { |
| 242 | this.entries = newEntries; |
| 243 | return this; |
| 244 | } |
| 245 | |
| 246 | return new ArrayMapNode(ownerID, newEntries); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | class BitmapIndexedNode { |