/** * Returns the least power of two smaller than or equal to 2<sup>30</sup> and larger than or equal to <code>Math.ceil( expected / f )</code>. * * @param expected the expected number of elements in a hash table. * @param f the load factor. * @return the minimum possible size for a backing array. * @throws IllegalArgumentException if the necessary size is larger than 2<sup>30</sup>. */ public static int arraySize(final int expected, final float f) { final long s = Math.max(2, HashCommon.nextPowerOfTwo((long) Math.ceil(expected / f))); if (s > 1 << 30) throw new IllegalArgumentException("Too large (" + expected + " expected elements with load factor " + f + ")"); return (int) s; }
/** * Returns the least power of two smaller than or equal to 2<sup>30</sup> and larger than or equal to <code>Math.ceil( expected / f )</code>. * * @param expected the expected number of elements in a hash table. * @param f the load factor. * @return the minimum possible size for a backing array. * @throws IllegalArgumentException if the necessary size is larger than 2<sup>30</sup>. */ public static int arraySize(final int expected, final float f) { final long s = Math.max(2, HashCommon.nextPowerOfTwo((long) Math.ceil(expected / f))); if (s > (1 << 30)) throw new IllegalArgumentException("Too large (" + expected + " expected elements with load factor " + f + ")"); return (int) s; }
public boolean containsKey(final int k) { if (k == 0) return containsNullKey; int curr; final int[] key = this.key; int pos; // The starting point. if ((curr = key[pos = HashCommon.mix(k) & mask]) == 0) return false; if (k == curr) return true; // There's always an unused entry. while (true) { if ((curr = key[pos = (pos + 1) & mask]) == 0) return false; if (k == curr) return true; } }
/** * Returns the least power of two smaller than or equal to 2<sup>30</sup> and larger than or equal to <code>Math.ceil( expected / f )</code>. * * @param expected the expected number of elements in a hash table. * @param f the load factor. * @return the minimum possible size for a backing array. * @throws IllegalArgumentException if the necessary size is larger than 2<sup>30</sup>. */ public static int arraySize(final int expected, final float f) { final long s = Math.max(2, HashCommon.nextPowerOfTwo((long) Math.ceil(expected / f))); if (s > 1 << 30) throw new IllegalArgumentException("Too large (" + expected + " expected elements with load factor " + f + ")"); return (int) s; }
public double get(final int k) { if (k == 0) return containsNullKey ? value[n] : defRetValue; int curr; final int[] key = this.key; int pos; // The starting point. if ((curr = key[pos = HashCommon.mix(k) & mask]) == 0) return defRetValue; if (k == curr) return value[pos]; // There's always an unused entry. while (true) { if ((curr = key[pos = (pos + 1) & mask]) == 0) return defRetValue; if (k == curr) return value[pos]; } }
/** * Returns the least power of two smaller than or equal to 2<sup>30</sup> and larger than or equal to <code>Math.ceil( expected / f )</code>. * * @param expected the expected number of elements in a hash table. * @param f the load factor. * @return the minimum possible size for a backing array. * @throws IllegalArgumentException if the necessary size is larger than 2<sup>30</sup>. */ public static int arraySize(final int expected, final float f) { final long s = Math.max(2, HashCommon.nextPowerOfTwo((long) Math.ceil(expected / f))); if (s > (1 << 30)) throw new IllegalArgumentException("Too large (" + expected + " expected elements with load factor " + f + ")"); return (int) s; }
public Double get(final Integer ok) { final int k = ok; if (k == 0) return containsNullKey ? value[n] : null; int curr; final int[] key = this.key; int pos; // The starting point. if ((curr = key[pos = HashCommon.mix(k) & mask]) == 0) return null; if (k == curr) return value[pos]; // There's always an unused entry. while (true) { if ((curr = key[pos = (pos + 1) & mask]) == 0) return null; if (k == curr) return value[pos]; } }
/** * Returns the least power of two smaller than or equal to 2<sup>30</sup> and larger than or equal to <code>Math.ceil( expected / f )</code>. *re * @param expected the expected number of elements in a hash table. * @param f the load factor. * @return the minimum possible size for a backing array. * @throws IllegalArgumentException if the necessary size is larger than 2<sup>30</sup>. */ public static int arraySize(final int expected, final float f) { final long s = Math.max(2, HashCommon.nextPowerOfTwo((long) Math.ceil(expected / f))); if (s > (1 << 30)) throw new IllegalArgumentException("Too large (" + expected + " expected elements with load factor " + f + ")"); return (int) s; }
public int get(final int k) { if (k == 0) return containsNullKey ? value[n] : defRetValue; int curr; final int[] key = this.key; int pos; // The starting point. if ((curr = key[pos = (HashCommon.mix(k)) & mask]) == 0) return defRetValue; if (k == curr) return value[pos]; // There's always an unused entry. while (true) { if ((curr = key[pos = (pos + 1) & mask]) == 0) return defRetValue; if (k == curr) return value[pos]; } }
/** * Returns the least power of two smaller than or equal to 2<sup>30</sup> and larger than or equal to <code>Math.ceil( expected / f )</code>. * * @param expected the expected number of elements in a hash table. * @param f the load factor. * @return the minimum possible size for a backing array. * @throws IllegalArgumentException if the necessary size is larger than 2<sup>30</sup>. */ public static int arraySize(final int expected, final float f) { final long s = Math.max(2, HashCommon.nextPowerOfTwo((long) Math.ceil(expected / f))); if (s > (1 << 30)) throw new IllegalArgumentException("Too large (" + expected + " expected elements with load factor " + f + ")"); return (int) s; }
public int getOrDefault(final int k, final int defaultValue) { if (k == 0) return containsNullKey ? value[n] : defaultValue; int curr; final int[] key = this.key; int pos; // The starting point. if ((curr = key[pos = (HashCommon.mix(k)) & mask]) == 0) return defaultValue; if (k == curr) return value[pos]; // There's always an unused entry. while (true) { if ((curr = key[pos = (pos + 1) & mask]) == 0) return defaultValue; if (k == curr) return value[pos]; } }
/** * Returns the least power of two smaller than or equal to 2<sup>30</sup> and larger than or equal to <code>Math.ceil( expected / f )</code>. * * @param expected the expected number of elements in a hash table. * @param f the load factor. * @return the minimum possible size for a backing array. * @throws IllegalArgumentException if the necessary size is larger than 2<sup>30</sup>. */ public static int arraySize(final int expected, final float f) { final long s = Math.max(2, HashCommon.nextPowerOfTwo((long) Math.ceil(expected / f))); if (s > (1 << 30)) throw new IllegalArgumentException("Too large (" + expected + " expected elements with load factor " + f + ")"); return (int) s; }
public boolean containsKey(final int k) { if (k == 0) return containsNullKey; int curr; final int[] key = this.key; int pos; // The starting point. if ((curr = key[pos = (HashCommon.mix(k)) & mask]) == 0) return false; if (k == curr) return true; // There's always an unused entry. while (true) { if ((curr = key[pos = (pos + 1) & mask]) == 0) return false; if (k == curr) return true; } } public boolean containsValue(final int v) {
/** * Returns the least power of two smaller than or equal to 2<sup>30</sup> and larger than or equal to <code>Math.ceil( expected / f )</code>. * * @param expected the expected number of elements in a hash table. * @param f the load factor. * @return the minimum possible size for a backing array. * @throws IllegalArgumentException if the necessary size is larger than 2<sup>30</sup>. */ public static int arraySize(final int expected, final float f) { final long s = Math.max(2, HashCommon.nextPowerOfTwo((long) Math.ceil(expected / f))); if (s > (1 << 30)) throw new IllegalArgumentException("Too large (" + expected + " expected elements with load factor " + f + ")"); return (int) s; }
protected int positionOf(final int k) { if (k == 0) { if(containsNullKey) return n; else return -1; } int curr; final int[] key = this.key; int pos; // The starting point. if ((curr = key[pos = (HashCommon.mix(k)) & mask]) == 0) return -1; if (k == curr) return pos; // There's always an unused entry. while (true) { if ((curr = key[pos = pos + 1 & mask]) == 0) return -1; if (k == curr) return pos; } }
private void tryCapacity(final long capacity) { final int needed = (int) Math.min( 1 << 30, Math.max(2, HashCommon.nextPowerOfTwo((long) Math.ceil(capacity / f)))); if (needed > n) rehash(needed); } private int removeEntry(final int pos) {
/** * Returns a hash code for this map. * * @return a hash code for this map. */ public int hashCode() { int h = 0; for (int j = realSize(), i = 0, t = 0; j-- != 0;) { while (key[i] == 0) i++; t = HashCommon.mix(key[i]) ^ HashCommon.mix(value[i] ^ HashCommon.INV_INT_PHI); h += t; i++; } // Zero / null keys have hash zero. if (containsNullKey) h += HashCommon.mix(value[n] ^ HashCommon.INV_INT_PHI); return h; }
private void tryCapacity(final long capacity) { final int needed = (int) Math.min( 1 << 30, Math.max(2, HashCommon.nextPowerOfTwo((long) Math.ceil(capacity / f)))); if (needed > n) rehash(needed); } private int removeEntry(final int pos) {
@SuppressWarnings("unchecked") public boolean contains(final Object o) { if (!(o instanceof Entry)) return false; final Entry<Integer, Double> e = (Entry<Integer, Double>) o; final int k = e.getKey(); if (k == 0) return IntDoubleOrderedMap.this.containsNullKey && (value[n] == e.getValue()); int curr; final int[] key = IntDoubleOrderedMap.this.key; int pos; // The starting point. if ((curr = key[pos = HashCommon.mix(k) & mask]) == 0) return false; if (k == curr) return value[pos] == e.getValue(); // There's always an unused entry. while (true) { if ((curr = key[pos = (pos + 1) & mask]) == 0) return false; if (k == curr) return value[pos] == e.getValue(); } }