final int idealSlot = hashKey(existing); final int shift = (slot - idealSlot) & mask; if (shift >= distance) {
/** * {@inheritDoc} */ @Override public VType getOrDefault(KType key, VType defaultValue) { if (((key) == null)) { return hasEmptyKey ? (VType) values[mask + 1] : defaultValue; } else { final KType[] keys = (KType[]) this.keys; final int mask = this.mask; int slot = hashKey(key) & mask; KType existing; while (!((existing = keys[slot]) == null)) { if (this.equals(existing, key)) { return (VType) values[slot]; } slot = (slot + 1) & mask; } return defaultValue; } }
/** * {@inheritDoc} */ @Override public VType get(KType key) { if (((key) == null)) { return hasEmptyKey ? (VType) values[mask + 1] : null; } else { final KType[] keys = (KType[]) this.keys; final int mask = this.mask; int slot = hashKey(key) & mask; KType existing; while (!((existing = keys[slot]) == null)) { if (this.equals(existing, key)) { return (VType) values[slot]; } slot = (slot + 1) & mask; } return null; } }
/** * {@inheritDoc} */ @Override public int indexOf(KType key) { final int mask = this.mask; if (((key) == null)) { return hasEmptyKey ? mask + 1 : ~(mask + 1); } else { final KType[] keys = (KType[]) this.keys; int slot = hashKey(key) & mask; KType existing; while (!((existing = keys[slot]) == null)) { if (this.equals(existing, key)) { return slot; } slot = (slot + 1) & mask; } return ~slot; } }
/** * {@inheritDoc} */ @Override public boolean containsKey(KType key) { if (((key) == null)) { return hasEmptyKey; } else { final KType[] keys = (KType[]) this.keys; final int mask = this.mask; int slot = hashKey(key) & mask; KType existing; while (!((existing = keys[slot]) == null)) { if (this.equals(existing, key)) { return true; } slot = (slot + 1) & mask; } return false; } }
/** * Rehash from old buffers to new buffers. */ protected void rehash(KType[] fromKeys, VType[] fromValues) { assert fromKeys.length == fromValues.length && HashContainers.checkPowerOfTwo(fromKeys.length - 1); // Rehash all stored key/value pairs into the new buffers. final KType[] keys = (KType[]) this.keys; final VType[] values = (VType[]) this.values; final int mask = this.mask; KType existing; // Copy the zero element's slot, then rehash everything else. int from = fromKeys.length - 1; keys[keys.length - 1] = fromKeys[from]; values[values.length - 1] = fromValues[from]; while (--from >= 0) { if (!((existing = fromKeys[from]) == null)) { int slot = hashKey(existing) & mask; while (!((keys[slot]) == null)) { slot = (slot + 1) & mask; } keys[slot] = existing; values[slot] = fromValues[from]; } } }
/** * {@inheritDoc} */ @Override public VType remove(KType key) { final int mask = this.mask; if (((key) == null)) { hasEmptyKey = false; VType previousValue = (VType) values[mask + 1]; values[mask + 1] = null; return previousValue; } else { final KType[] keys = (KType[]) this.keys; int slot = hashKey(key) & mask; KType existing; while (!((existing = keys[slot]) == null)) { if (this.equals(existing, key)) { final VType previousValue = (VType) values[slot]; shiftConflictingKeys(slot); return previousValue; } slot = (slot + 1) & mask; } return null; } }
} else { final KType[] keys = (KType[]) this.keys; int slot = hashKey(key) & mask;
final int idealSlot = hashKey(existing); final int shift = (slot - idealSlot) & mask; if (shift >= distance) {
/** * {@inheritDoc} */ @Override public VType getOrDefault(KType key, VType defaultValue) { if (((key) == null)) { return hasEmptyKey ? (VType) values[mask + 1] : defaultValue; } else { final KType[] keys = (KType[]) this.keys; final int mask = this.mask; int slot = hashKey(key) & mask; KType existing; while (!((existing = keys[slot]) == null)) { if (this.equals(existing, key)) { return (VType) values[slot]; } slot = (slot + 1) & mask; } return defaultValue; } }
/** * {@inheritDoc} */ @Override public boolean containsKey(KType key) { if (((key) == null)) { return hasEmptyKey; } else { final KType[] keys = (KType[]) this.keys; final int mask = this.mask; int slot = hashKey(key) & mask; KType existing; while (!((existing = keys[slot]) == null)) { if (this.equals(existing, key)) { return true; } slot = (slot + 1) & mask; } return false; } }
/** * {@inheritDoc} */ @Override public VType get(KType key) { if (((key) == null)) { return hasEmptyKey ? (VType) values[mask + 1] : null; } else { final KType[] keys = (KType[]) this.keys; final int mask = this.mask; int slot = hashKey(key) & mask; KType existing; while (!((existing = keys[slot]) == null)) { if (this.equals(existing, key)) { return (VType) values[slot]; } slot = (slot + 1) & mask; } return null; } }
/** * {@inheritDoc} */ @Override public int indexOf(KType key) { final int mask = this.mask; if (((key) == null)) { return hasEmptyKey ? mask + 1 : ~(mask + 1); } else { final KType[] keys = (KType[]) this.keys; int slot = hashKey(key) & mask; KType existing; while (!((existing = keys[slot]) == null)) { if (this.equals(existing, key)) { return slot; } slot = (slot + 1) & mask; } return ~slot; } }
/** * Rehash from old buffers to new buffers. */ protected void rehash(KType[] fromKeys, VType[] fromValues) { assert fromKeys.length == fromValues.length && HashContainers.checkPowerOfTwo(fromKeys.length - 1); // Rehash all stored key/value pairs into the new buffers. final KType[] keys = (KType[]) this.keys; final VType[] values = (VType[]) this.values; final int mask = this.mask; KType existing; // Copy the zero element's slot, then rehash everything else. int from = fromKeys.length - 1; keys[keys.length - 1] = fromKeys[from]; values[values.length - 1] = fromValues[from]; while (--from >= 0) { if (!((existing = fromKeys[from]) == null)) { int slot = hashKey(existing) & mask; while (!((keys[slot]) == null)) { slot = (slot + 1) & mask; } keys[slot] = existing; values[slot] = fromValues[from]; } } }
/** * {@inheritDoc} */ @Override public VType remove(KType key) { final int mask = this.mask; if (((key) == null)) { hasEmptyKey = false; VType previousValue = (VType) values[mask + 1]; values[mask + 1] = null; return previousValue; } else { final KType[] keys = (KType[]) this.keys; int slot = hashKey(key) & mask; KType existing; while (!((existing = keys[slot]) == null)) { if (this.equals(existing, key)) { final VType previousValue = (VType) values[slot]; shiftConflictingKeys(slot); return previousValue; } slot = (slot + 1) & mask; } return null; } }
} else { final KType[] keys = (KType[]) this.keys; int slot = hashKey(key) & mask;