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