MCPcopy Index your code
hub / github.com/clojure/clojure / ArrayNode

Class ArrayNode

src/jvm/clojure/lang/PersistentHashMap.java:403–673  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

401}
402
403final static class ArrayNode implements INode{
404 int count;
405 final INode[] array;
406 final AtomicReference<Thread> edit;
407
408 ArrayNode(AtomicReference<Thread> edit, int count, INode[] array){
409 this.array = array;
410 this.edit = edit;
411 this.count = count;
412 }
413
414 public INode assoc(int shift, int hash, Object key, Object val, Box addedLeaf){
415 int idx = mask(hash, shift);
416 INode node = array[idx];
417 if(node == null)
418 return new ArrayNode(null, count + 1, cloneAndSet(array, idx, BitmapIndexedNode.EMPTY.assoc(shift + 5, hash, key, val, addedLeaf)));
419 INode n = node.assoc(shift + 5, hash, key, val, addedLeaf);
420 if(n == node)
421 return this;
422 return new ArrayNode(null, count, cloneAndSet(array, idx, n));
423 }
424
425 public INode without(int shift, int hash, Object key){
426 int idx = mask(hash, shift);
427 INode node = array[idx];
428 if(node == null)
429 return this;
430 INode n = node.without(shift + 5, hash, key);
431 if(n == node)
432 return this;
433 if (n == null) {
434 if (count <= 8) // shrink
435 return pack(null, idx);
436 return new ArrayNode(null, count - 1, cloneAndSet(array, idx, n));
437 } else
438 return new ArrayNode(null, count, cloneAndSet(array, idx, n));
439 }
440
441 public IMapEntry find(int shift, int hash, Object key){
442 int idx = mask(hash, shift);
443 INode node = array[idx];
444 if(node == null)
445 return null;
446 return node.find(shift + 5, hash, key);
447 }
448
449 public Object find(int shift, int hash, Object key, Object notFound){
450 int idx = mask(hash, shift);
451 INode node = array[idx];
452 if(node == null)
453 return notFound;
454 return node.find(shift + 5, hash, key, notFound);
455 }
456
457 public ISeq nodeSeq(){
458 return Seq.create(array);
459 }
460

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected