public PersistentMap<Long, V> delete(long key) { IntMap<MapEntry<Long, V>> im = getInner(key); if (im == null) return this; int lo = Bits.lowWord(key); if (!im.containsKey(lo)) return this; IntMap<MapEntry<Long, V>> newInnerMap = im.delete(lo); assert (newInnerMap != im); IntMap<IntMap<MapEntry<Long, V>>> newData = data.include(Bits.highWord(key), newInnerMap); return new LongMap<V>(newData, count - 1); }
@Override public boolean containsKey(Object key) { long k = toKey(key); IntMap<MapEntry<Long, V>> im = getInner(k); if (im == null) return false; return im.containsKey(Bits.lowWord(k)); }
public V get(long key) { IntMap<MapEntry<Long, V>> im = getInner(key); if (im == null) return null; MapEntry<Long, V> entry = im.get(Bits.lowWord(key)); if (entry == null) return null; return entry.getValue(); }
@Override public java.util.Map.Entry<Long, V> getMapEntry(Object key) { long k = toKey(key); IntMap<MapEntry<Long, V>> im = getInner(k); if (im == null) return null; MapEntry<Long, V> entry = im.get(Bits.lowWord(k)); if (entry == null) return null; return entry; }
@Override public PersistentMap<Long, V> include(Long key, V value) { IntMap<MapEntry<Long, V>> im = getInner(key); MapEntry<Long, V> entry = new MapEntry<Long, V>(key, value); long newCount = count; int lo = Bits.lowWord(key); if (im == null) { im = IntMap.create(lo, entry); newCount += 1; } else { if (!im.containsKey(lo)) newCount++; im = im.include(lo, entry); } IntMap<IntMap<MapEntry<Long, V>>> newData = data.include(Bits.highWord(key), im); if (data == newData) return this; return new LongMap<V>(newData, newCount); }
@Override public V get(Object key) { long k = toKey(key); IntMap<MapEntry<Long, V>> im = getInner(k); if (im == null) return null; MapEntry<Long, V> entry = im.get(Bits.lowWord(k)); if (entry == null) return null; return entry.getValue(); }
private IntMap<MapEntry<Long, V>> getInner(long key) { return data.get(Bits.highWord(key)); }