@Override public char getChar(Object key) { int index = index(key); if (index >= 0) { // key is present return values[index]; } else { // key is absent return defaultValue(); } }
@Override public char putIfAbsent(K key, char value) { int index = insert(key, value); if (index < 0) { // key was absent return defaultValue(); } else { // key is present return values[index]; } }
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] = newValue; postInsertHook(); return newValue; } else { return computeNullKey(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] = value; postInsertHook(); return value; } else { return computeIfAbsentNullKey(mappingFunction);
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] = value; postInsertHook(); return value; return newValue; } else { return mergeNullKey(value, remappingFunction);
@Override public void forEach(BiConsumer<? super K, ? super Character> action) { if (action == null) throw new java.lang.NullPointerException(); if (isEmpty()) return; int mc = modCount(); Object[] keys = set; char[] vals = values; for (int i = keys.length - 1; i >= 0; i--) { K key; // noinspection unchecked if ((key = (K) keys[i]) != FREE) { action.accept(key, vals[i]); } } if (mc != modCount()) throw new java.util.ConcurrentModificationException(); }
incrementModCount(); keys[index] = null; vals[index] = value; postInsertHook(); return value; } else {
@Override @Nonnull public <K2 extends K> UpdatableLHashSeparateKVObjCharMapGO<K2> newUpdatableMap( Map<? extends K2, Character> map, int expectedSize) { if (map instanceof ObjCharMap) { // noinspection unchecked ObjCharMap<K2> objCharMap = (ObjCharMap<K2>) map; if (map instanceof SeparateKVObjCharLHash) { SeparateKVObjCharLHash hash = (SeparateKVObjCharLHash) map; if (hash.hashConfig().equals(hashConf) && objCharMap.keyEquivalence().equals(getKeyEquivalence())) { UpdatableLHashSeparateKVObjCharMapGO<K2> res = uninitializedUpdatableMap(); res.copy(hash); return res; } } UpdatableLHashSeparateKVObjCharMapGO<K2> res = newUpdatableMap(expectedSize); res.putAll(map); return res; } else { UpdatableLHashSeparateKVObjCharMapGO<K2> res = newUpdatableMap(expectedSize); for (Map.Entry<? extends K2, Character> entry : map.entrySet()) { res.put(entry.getKey(), entry.getValue()); } return res; } } }
@Override void rehash(int newCapacity) { int mc = modCount(); Object[] keys = set; char[] vals = values; initForRehash(newCapacity); mc++; // modCount is incremented in initForRehash() Object[] newKeys = set; int capacityMask = newKeys.length - 1; char[] 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(); }
@Override public String toString() { if (isEmpty()) return "{}"; StringBuilder sb = new StringBuilder(); int elementCount = 0; int mc = modCount(); Object[] keys = set; char[] 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(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(); }
char newValue = remappingFunction.applyAsChar(null, defaultValue()); incrementModCount(); keys[index] = null; vals[index] = newValue; postInsertHook(); return newValue;
@Override public Character get(Object key) { int index = index(key); if (index >= 0) { // key is present return values[index]; } else { // key is absent return null; } }
@Override public Character putIfAbsent(K key, Character value) { int index = insert(key, value); if (index < 0) { // key was absent return null; } else { // key is present return values[index]; } }
@Override @Nonnull public <K2 extends K> UpdatableLHashSeparateKVObjCharMapGO<K2> newUpdatableMap( int expectedSize) { UpdatableLHashSeparateKVObjCharMapGO<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; char newValue = remappingFunction.applyAsChar(key, defaultValue()); incrementModCount(); keys[index] = key; vals[index] = newValue; postInsertHook(); return newValue; return newValue; } else { return computeNullKey(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] = value; postInsertHook(); return value; return computeIfAbsentNullKey(mappingFunction);
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] = value; postInsertHook(); return value; return newValue; } else { return mergeNullKey(value, remappingFunction);
@Override public void replaceAll( BiFunction<? super K, ? super Character, ? extends Character> function) { if (function == null) throw new java.lang.NullPointerException(); if (isEmpty()) return; int mc = modCount(); Object[] keys = set; char[] vals = values; for (int i = keys.length - 1; i >= 0; i--) { K key; // noinspection unchecked if ((key = (K) keys[i]) != FREE) { vals[i] = function.apply(key, vals[i]); } } if (mc != modCount()) throw new java.util.ConcurrentModificationException(); }
incrementModCount(); keys[index] = null; vals[index] = value; postInsertHook(); return value;
@Override @Nonnull public <K2 extends K> UpdatableLHashSeparateKVObjCharMapGO<K2> newUpdatableMap( Map<? extends K2, Character> map, int expectedSize) { if (map instanceof ObjCharMap) { // noinspection unchecked ObjCharMap<K2> objCharMap = (ObjCharMap<K2>) map; if (map instanceof SeparateKVObjCharLHash) { SeparateKVObjCharLHash hash = (SeparateKVObjCharLHash) map; if (hash.hashConfig().equals(hashConf) && objCharMap.keyEquivalence().equals(getKeyEquivalence())) { UpdatableLHashSeparateKVObjCharMapGO<K2> res = uninitializedUpdatableMap(); res.copy(hash); return res; } } UpdatableLHashSeparateKVObjCharMapGO<K2> res = newUpdatableMap(expectedSize); res.putAll(map); return res; } else { UpdatableLHashSeparateKVObjCharMapGO<K2> res = newUpdatableMap(expectedSize); for (Map.Entry<? extends K2, Character> entry : map.entrySet()) { res.put(entry.getKey(), entry.getValue()); } return res; } } }