public static PersistentHashMap createPersistentHashMap(int count, Object root) { return new PersistentHashMap(count, (INode)root, false, null); }
public PersistentHashMap withMeta(IPersistentMap meta){ return new PersistentHashMap(meta, count, root, hasNull, nullValue); }
IPersistentMap doPersistent() { edit.set(null); return new PersistentHashMap(count, root, hasNull, nullValue); }
IPersistentMap doPersistent() { edit.set(null); return new PersistentHashMap(count, root, 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 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 static PersistentHashMap assocBy(PersistentHashMap map, Resolver resolver, Object key, Object value) { final Counts counts = new Counts(resolver, 0, 0); final PersistentHashMap.INode oldRoot = map.root == null? BitmapIndexedNode.EMPTY : map.root; final PersistentHashMap.INode newRoot = Seqspert.splice(0, counts, false, 0, null, oldRoot, false, 0, key, value); return (newRoot == oldRoot) ? map : new PersistentHashMap(map.count + 1 - counts.sameKey, newRoot, map.hasNull, map.nullValue); }
public static PersistentHashMap spliceHashMaps(PersistentHashMap lMap, PersistentHashMap rMap) { // check null config the same final INode lRoot = lMap.root; final INode rRoot = rMap.root; if (lRoot == null) return rMap; else if (rRoot == null) return lMap; final Counts counts = new Counts(Counts.leftResolver, 0, 0); // TODO: pass through correct resolveFn here final PersistentHashMap.INode root = Seqspert.splice(0, counts, false, 0, null, lRoot, false, 0, null, rRoot); final int count = lMap.count + rMap.count - counts.sameKey; // TODO - do NOT always reurn new map return new PersistentHashMap(count, root, lMap.hasNull, lMap.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); }
final IPersistentMap _meta; final public static PersistentHashMap EMPTY = new PersistentHashMap(0, null, false, null); final private static Object NOT_FOUND = new Object();