public Response send (String... kvs) { try { Map msg = PersistentHashMap.createWithCheck(kvs); return new Response((ISeq)message.invoke(client, msg)); } catch (Exception e) { throw new RuntimeException(e); } }
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 int hash(Object key) { if (key == null) throw new IllegalArgumentException("hash() called on null"); // should be assertion return PersistentHashMap.hash(key); }
static public IPersistentMap mapUniqueKeys(Object... init){ if(init == null) return PersistentArrayMap.EMPTY; else if(init.length <= PersistentArrayMap.HASHTABLE_THRESHOLD) return new PersistentArrayMap(init); return PersistentHashMap.create(init); }
private static int bitpos(int hash, int shift){ return 1 << mask(hash, shift); }
ITransientMap doAssoc(Object key, Object val){ int i = indexOf(key); if(i >= 0) //already have key, { if(array[i + 1] != val) //no change, no op array[i + 1] = val; } else //didn't have key, grow { if(len >= array.length) return PersistentHashMap.create(array).asTransient().assoc(key, val); array[len++] = key; array[len++] = val; } return this; }
public static PersistentHashMap createPersistentHashMap(int count, Object root) { return new PersistentHashMap(count, (INode)root, false, null); }
public ITransientCollection asTransient() { return new TransientHashSet(((PersistentHashMap) impl).asTransient()); }
public IPersistentMap assocEx(Object key, Object val) { if(containsKey(key)) throw Util.runtimeException("Key already present"); return assoc(key, val); }
@Override public Expression optimise() { Expression b=body.optimise(); Expression v=value.optimise(); if (value.isPure()) { IPersistentSet bfree= b.accumulateFreeSymbols(PersistentHashSet.EMPTY); if (!(bfree.contains(sym))) { return b; } if (value.isConstant()) { return b.substitute(PersistentHashMap.EMPTY.assoc(sym,value.eval())).optimise(); } } return update(sym,v,b); }
public Object valAt(Object key){ return valAt(key, null); }
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 Object valAt(Object key, Object notFound){ if(key == null) return hasNull ? nullValue : notFound; return root != null ? root.find(0, hash(key), key, notFound) : notFound; }
@SuppressWarnings("unchecked") static <K, V> ClojureMap<K, V> create(Object... init) { return (ClojureMap<K, V>) create(PersistentHashMap.create(init)); }
private static int bitpos(int hash, int shift){ return 1 << mask(hash, shift); }
ITransientMap doAssoc(Object key, Object val){ int i = indexOf(key); if(i >= 0) //already have key, { if(array[i + 1] != val) //no change, no op array[i + 1] = val; } else //didn't have key, grow { if(len >= array.length) return PersistentHashMap.create(array).asTransient().assoc(key, val); array[len++] = key; array[len++] = val; } return this; }