MCPcopy
hub / github.com/immutable-js/immutable-js / update

Method update

src/Map.js:273–336  ·  view source on GitHub ↗
(ownerID, shift, keyHash, key, value, didChangeSize, didAlter)

Source from the content-addressed store, hash-verified

271 }
272
273 update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
274 if (keyHash === undefined) {
275 keyHash = hash(key);
276 }
277 const keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
278 const bit = 1 << keyHashFrag;
279 const bitmap = this.bitmap;
280 const exists = (bitmap & bit) !== 0;
281
282 if (!exists && value === NOT_SET) {
283 return this;
284 }
285
286 const idx = popCount(bitmap & (bit - 1));
287 const nodes = this.nodes;
288 const node = exists ? nodes[idx] : undefined;
289 const newNode = updateNode(
290 node,
291 ownerID,
292 shift + SHIFT,
293 keyHash,
294 key,
295 value,
296 didChangeSize,
297 didAlter
298 );
299
300 if (newNode === node) {
301 return this;
302 }
303
304 if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
305 return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
306 }
307
308 if (
309 exists &&
310 !newNode &&
311 nodes.length === 2 &&
312 isLeafNode(nodes[idx ^ 1])
313 ) {
314 return nodes[idx ^ 1];
315 }
316
317 if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
318 return newNode;
319 }
320
321 const isEditable = ownerID && ownerID === this.ownerID;
322 const newBitmap = exists ? (newNode ? bitmap : bitmap ^ bit) : bitmap | bit;
323 const newNodes = exists
324 ? newNode
325 ? setAt(nodes, idx, newNode, isEditable)
326 : spliceOut(nodes, idx, isEditable)
327 : spliceIn(nodes, idx, newNode, isEditable);
328
329 if (isEditable) {
330 this.bitmap = newBitmap;

Callers

nothing calls this directly

Calls 8

hashFunction · 0.90
popCountFunction · 0.85
updateNodeFunction · 0.85
expandNodesFunction · 0.85
isLeafNodeFunction · 0.85
setAtFunction · 0.85
spliceOutFunction · 0.85
spliceInFunction · 0.85

Tested by

no test coverage detected