public static int hash(Object key) { if (key == null) throw new IllegalArgumentException("hash() called on null"); // should be assertion return PersistentHashMap.hash(key); }
public boolean containsKey(Object key){ if(key == null) return hasNull; return (root != null) ? root.find(0, hash(key), key, NOT_FOUND) != NOT_FOUND : false; }
public boolean containsKey(Object key){ if(key == null) return hasNull; return (root != null) ? root.find(0, hash(key), key, NOT_FOUND) != NOT_FOUND : false; }
public Object valAt(Object key, Object notFound){ if(key == null) return hasNull ? nullValue : notFound; return root != null ? root.find(0, hash(key), key, notFound) : notFound; }
Object doValAt(Object key, Object notFound) { if (key == null) if (hasNull) return nullValue; else return notFound; if (root == null) return notFound; return root.find(0, hash(key), key, notFound); }
public Object valAt(Object key, Object notFound){ if(key == null) return hasNull ? nullValue : notFound; return root != null ? root.find(0, hash(key), key, notFound) : notFound; }
public IMapEntry entryAt(Object key){ if(key == null) return hasNull ? new MapEntry(null, nullValue) : null; return (root != null) ? root.find(0, hash(key), key) : null; }
ITransientMap doWithout(Object key) { if (key == null) { if (!hasNull) return this; hasNull = false; nullValue = null; this.count--; return this; } if (root == null) return this; // Box leafFlag = new Box(null); leafFlag.val = null; INode n = root.without(edit, 0, hash(key), key, leafFlag); if (n != root) this.root = n; if(leafFlag.val != null) this.count--; return this; }
ITransientMap doAssoc(Object key, Object val) { if (key == null) { if (this.nullValue != val) this.nullValue = val; if (!hasNull) { this.count++; this.hasNull = true; } return this; } // Box leafFlag = new Box(null); leafFlag.val = null; INode n = (root == null ? BitmapIndexedNode.EMPTY : root) .assoc(edit, 0, hash(key), key, val, leafFlag); if (n != this.root) this.root = n; if(leafFlag.val != null) this.count++; return this; }
public IMapEntry entryAt(Object key){ if(key == null) return hasNull ? new MapEntry(null, nullValue) : null; return (root != null) ? root.find(0, hash(key), key) : null; }
private static INode createNode(int shift, Object key1, Object val1, int key2hash, Object key2, Object val2) { int key1hash = hash(key1); if(key1hash == key2hash) return new HashCollisionNode(null, key1hash, 2, new Object[] {key1, val1, key2, val2}); Box addedLeaf = new Box(null); AtomicReference<Thread> edit = new AtomicReference<Thread>(); return BitmapIndexedNode.EMPTY .assoc(edit, shift, key1hash, key1, val1, addedLeaf) .assoc(edit, shift, key2hash, key2, val2, addedLeaf); }
private static INode createNode(AtomicReference<Thread> edit, int shift, Object key1, Object val1, int key2hash, Object key2, Object val2) { int key1hash = hash(key1); if(key1hash == key2hash) return new HashCollisionNode(null, key1hash, 2, new Object[] {key1, val1, key2, val2}); Box addedLeaf = new Box(null); return BitmapIndexedNode.EMPTY .assoc(edit, shift, key1hash, key1, val1, addedLeaf) .assoc(edit, shift, key2hash, key2, val2, addedLeaf); }
public IPersistentMap without(Object key){ if(key == null) return hasNull ? new PersistentHashMap(meta(), count - 1, root, false, null) : this; if(root == null) return this; INode newroot = root.without(0, hash(key), key); if(newroot == root) return this; return new PersistentHashMap(meta(), count - 1, newroot, hasNull, nullValue); }
public IPersistentMap without(Object key){ if(key == null) return hasNull ? new PersistentHashMap(meta(), count - 1, root, false, null) : this; if(root == null) return this; INode newroot = root.without(0, hash(key), key); if(newroot == root) return this; return new PersistentHashMap(meta(), count - 1, newroot, hasNull, nullValue); }
public IPersistentMap assoc(Object key, Object val){ if(key == null) { if(hasNull && val == nullValue) return this; return new PersistentHashMap(meta(), hasNull ? count : count + 1, root, true, val); } Box addedLeaf = new Box(null); INode newroot = (root == null ? BitmapIndexedNode.EMPTY : root) .assoc(0, hash(key), key, val, addedLeaf); if(newroot == root) return this; return new PersistentHashMap(meta(), addedLeaf.val == null ? count : count + 1, newroot, hasNull, nullValue); }
public IPersistentMap assoc(Object key, Object val){ if(key == null) { if(hasNull && val == nullValue) return this; return new PersistentHashMap(meta(), hasNull ? count : count + 1, root, true, val); } Box addedLeaf = new Box(null); INode newroot = (root == null ? BitmapIndexedNode.EMPTY : root) .assoc(0, hash(key), key, val, addedLeaf); if(newroot == root) return this; return new PersistentHashMap(meta(), addedLeaf.val == null ? count : count + 1, newroot, hasNull, nullValue); }
nodes[i] = (INode) array[j+1]; else nodes[i] = EMPTY.assoc(edit, shift + 5, hash(array[j]), array[j], array[j+1], addedLeaf); j += 2;
nodes[i] = (INode) array[j+1]; else nodes[i] = EMPTY.assoc(shift + 5, hash(array[j]), array[j], array[j+1], addedLeaf); j += 2;