@Override public double getDouble(Object key) { int index = index(key); if (index >= 0) { // key is present return Double.longBitsToDouble(values[index]); } else { // key is absent return defaultValue(); } }
@Override public double putIfAbsent(K key, double value) { int index = insert(key, Double.doubleToLongBits(value)); if (index < 0) { // key was absent return defaultValue(); } else { // key is present return Double.longBitsToDouble(values[index]); } }
@Override public void reversePutAllTo(InternalObjDoubleMapOps<? super K> m) { if (isEmpty()) return; int mc = modCount(); Object[] keys = set; long[] vals = values; for (int i = keys.length - 1; i >= 0; i--) { K key; // noinspection unchecked if ((key = (K) keys[i]) != FREE) { m.justPut(key, vals[i]); } } if (mc != modCount()) throw new java.util.ConcurrentModificationException(); }
K cur; keyPresent: if ((cur = keys[index = SeparateKVObjKeyMixing.mix(keyHashCode(key)) & (capacityMask = keys.length - 1)]) != key) { keyAbsent: if (cur != FREE) { if (keyEquals(key, cur)) { break keyPresent; } else { break keyAbsent; else if (keyEquals(key, cur)) { break keyPresent; double newValue = remappingFunction.applyAsDouble(key, defaultValue()); incrementModCount(); keys[index] = key; vals[index] = Double.doubleToLongBits(newValue); postInsertHook(); return newValue; return newValue; } else { return computeNullKey(remappingFunction);
K cur; keyPresent: if ((cur = keys[index = SeparateKVObjKeyMixing.mix(keyHashCode(key)) & (capacityMask = keys.length - 1)]) != key) { keyAbsent: if (cur != FREE) { if (keyEquals(key, cur)) { break keyPresent; } else { break keyAbsent; else if (keyEquals(key, cur)) { break keyPresent; incrementModCount(); keys[index] = key; vals[index] = Double.doubleToLongBits(value); postInsertHook(); return value; return newValue; } else { return mergeNullKey(value, remappingFunction);
int capacityMask, index; K cur; if ((cur = keys[index = SeparateKVObjKeyMixing.mix(keyHashCode(key)) & (capacityMask = keys.length - 1)]) == key) { keyAbsent: if (cur != FREE) { if (keyEquals(key, cur)) { break keyAbsent; else if (keyEquals(key, cur)) { incrementModCount(); keys[index] = key; vals[index] = Double.doubleToLongBits(value); postInsertHook(); return value; } else { return computeIfAbsentNullKey(mappingFunction);
incrementModCount(); keys[index] = null; vals[index] = Double.doubleToLongBits(value); postInsertHook(); return value; } else {
@Override @Nonnull public <K2 extends K> UpdatableLHashSeparateKVObjDoubleMapGO<K2> newUpdatableMap( Map<? extends K2, Double> map, int expectedSize) { if (map instanceof ObjDoubleMap) { // noinspection unchecked ObjDoubleMap<K2> objDoubleMap = (ObjDoubleMap<K2>) map; if (map instanceof SeparateKVObjDoubleLHash) { SeparateKVObjDoubleLHash hash = (SeparateKVObjDoubleLHash) map; if (hash.hashConfig().equals(hashConf) && objDoubleMap.keyEquivalence().equals(getKeyEquivalence())) { UpdatableLHashSeparateKVObjDoubleMapGO<K2> res = uninitializedUpdatableMap(); res.copy(hash); return res; } } UpdatableLHashSeparateKVObjDoubleMapGO<K2> res = newUpdatableMap(expectedSize); res.putAll(map); return res; } else { UpdatableLHashSeparateKVObjDoubleMapGO<K2> res = newUpdatableMap(expectedSize); for (Map.Entry<? extends K2, Double> entry : map.entrySet()) { res.put(entry.getKey(), entry.getValue()); } return res; } } }
@Override public String toString() { if (isEmpty()) return "{}"; StringBuilder sb = new StringBuilder(); int elementCount = 0; int mc = modCount(); Object[] keys = set; long[] vals = values; for (int i = keys.length - 1; i >= 0; i--) { K key; // noinspection unchecked if ((key = (K) keys[i]) != FREE) { sb.append(' '); sb.append(key != this ? key : "(this Map)"); sb.append('='); sb.append(Double.longBitsToDouble(vals[i])); sb.append(','); if (++elementCount == 8) { int expectedLength = sb.length() * (size() / 8); sb.ensureCapacity(expectedLength + (expectedLength / 2)); } } } if (mc != modCount()) throw new java.util.ConcurrentModificationException(); sb.setCharAt(0, '{'); sb.setCharAt(sb.length() - 1, '}'); return sb.toString(); }
@Override void rehash(int newCapacity) { int mc = modCount(); Object[] keys = set; long[] vals = values; initForRehash(newCapacity); mc++; // modCount is incremented in initForRehash() Object[] newKeys = set; int capacityMask = newKeys.length - 1; long[] newVals = values; for (int i = keys.length - 1; i >= 0; i--) { K key; // noinspection unchecked if ((key = (K) keys[i]) != FREE) { int index; if (newKeys[index = SeparateKVObjKeyMixing.mix(nullableKeyHashCode(key)) & capacityMask] != FREE) { while (true) { if (newKeys[(index = (index - 1) & capacityMask)] == FREE) { break; } } } newKeys[index] = key; newVals[index] = vals[i]; } } if (mc != modCount()) throw new java.util.ConcurrentModificationException(); }
double newValue = remappingFunction.applyAsDouble(null, defaultValue()); incrementModCount(); keys[index] = null; vals[index] = Double.doubleToLongBits(newValue); postInsertHook(); return newValue;
@Override public boolean containsEntry(Object key, long value) { int index = index(key); if (index >= 0) { // key is present return values[index] == value; } else { // key is absent return false; } }
@Override public void justPut(K key, long value) { int index = insert(key, value); if (index < 0) { // key was absent return; } else { // key is present values[index] = value; return; } }
@Override @Nonnull public <K2 extends K> UpdatableLHashSeparateKVObjDoubleMapGO<K2> newUpdatableMap( int expectedSize) { UpdatableLHashSeparateKVObjDoubleMapGO<K2> map = uninitializedUpdatableMap(); map.init(configWrapper, expectedSize); return map; }
K cur; keyPresent: if ((cur = keys[index = SeparateKVObjKeyMixing.mix(keyHashCode(key)) & (capacityMask = keys.length - 1)]) != key) { keyAbsent: if (cur != FREE) { if (keyEquals(key, cur)) { break keyPresent; } else { break keyAbsent; else if (keyEquals(key, cur)) { break keyPresent; incrementModCount(); keys[index] = key; vals[index] = Double.doubleToLongBits(newValue); postInsertHook(); return newValue; } else { return computeNullKey(remappingFunction);
K cur; keyPresent: if ((cur = keys[index = SeparateKVObjKeyMixing.mix(keyHashCode(key)) & (capacityMask = keys.length - 1)]) != key) { keyAbsent: if (cur != FREE) { if (keyEquals(key, cur)) { break keyPresent; } else { break keyAbsent; else if (keyEquals(key, cur)) { break keyPresent; incrementModCount(); keys[index] = key; vals[index] = Double.doubleToLongBits(value); postInsertHook(); return value; return mergeNullKey(value, remappingFunction);
int capacityMask, index; K cur; if ((cur = keys[index = SeparateKVObjKeyMixing.mix(keyHashCode(key)) & (capacityMask = keys.length - 1)]) == key) { keyAbsent: if (cur != FREE) { if (keyEquals(key, cur)) { break keyAbsent; else if (keyEquals(key, cur)) { incrementModCount(); keys[index] = key; vals[index] = Double.doubleToLongBits(value); postInsertHook(); return value; return computeIfAbsentNullKey(mappingFunction);
incrementModCount(); keys[index] = null; vals[index] = Double.doubleToLongBits(value); postInsertHook(); return value;
@Override @Nonnull public <K2 extends K> UpdatableLHashSeparateKVObjDoubleMapGO<K2> newUpdatableMap( Map<? extends K2, Double> map, int expectedSize) { if (map instanceof ObjDoubleMap) { // noinspection unchecked ObjDoubleMap<K2> objDoubleMap = (ObjDoubleMap<K2>) map; if (map instanceof SeparateKVObjDoubleLHash) { SeparateKVObjDoubleLHash hash = (SeparateKVObjDoubleLHash) map; if (hash.hashConfig().equals(hashConf) && objDoubleMap.keyEquivalence().equals(getKeyEquivalence())) { UpdatableLHashSeparateKVObjDoubleMapGO<K2> res = uninitializedUpdatableMap(); res.copy(hash); return res; } } UpdatableLHashSeparateKVObjDoubleMapGO<K2> res = newUpdatableMap(expectedSize); res.putAll(map); return res; } else { UpdatableLHashSeparateKVObjDoubleMapGO<K2> res = newUpdatableMap(expectedSize); for (Map.Entry<? extends K2, Double> entry : map.entrySet()) { res.put(entry.getKey(), entry.getValue()); } return res; } } }
@Override public String toString() { if (isEmpty()) return "{}"; StringBuilder sb = new StringBuilder(); int elementCount = 0; int mc = modCount(); Object[] keys = set; long[] vals = values; for (int i = keys.length - 1; i >= 0; i--) { K key; // noinspection unchecked if ((key = (K) keys[i]) != FREE) { sb.append(' '); sb.append(key != this ? key : "(this Map)"); sb.append('='); sb.append(Double.longBitsToDouble(vals[i])); sb.append(','); if (++elementCount == 8) { int expectedLength = sb.length() * (size() / 8); sb.ensureCapacity(expectedLength + (expectedLength / 2)); } } } if (mc != modCount()) throw new java.util.ConcurrentModificationException(); sb.setCharAt(0, '{'); sb.setCharAt(sb.length() - 1, '}'); return sb.toString(); }