// Need at least two slots, or hash() will break.
if (max < 2)
max = 2;
- table = new Object[2 * max];
+ table = new Object[max << 1];
Arrays.fill(table, emptyslot);
- threshold = max / 4 * 3;
+ threshold = (max >> 2) * 3;
}
/**
*/
public IdentityHashMap(Map m)
{
- this(Math.max(m.size() * 2, DEFAULT_CAPACITY));
+ this(Math.max(m.size() << 1, DEFAULT_CAPACITY));
putAll(m);
}
}
/**
- * Return the value in this Map associated with the supplied key,
- * or <pre>null</pre> if the key maps to nothing. NOTE: Since the value
- * could also be null, you must use containsKey to see if this key
- * actually maps to something. Unlike normal maps, this tests for the key
- * with <code>entry == key</code> instead of
- * <code>entry == null ? key == null : entry.equals(key)</code>.
+ * Return the value in this Map associated with the supplied key, or
+ * <code>null</code> if the key maps to nothing.
+ *
+ * <p>NOTE: Since the value could also be null, you must use
+ * containsKey to see if this key actually maps to something.
+ * Unlike normal maps, this tests for the key with <code>entry ==
+ * key</code> instead of <code>entry == null ? key == null :
+ * entry.equals(key)</code>.
*
* @param key the key for which to fetch an associated value
* @return what the key maps to, if present
Object[] old = table;
// This isn't necessarily prime, but it is an odd number of key/value
// slots, which has a higher probability of fewer collisions.
- table = new Object[old.length * 2 + 2];
+ table = new Object[old.length << 1 + 2];
Arrays.fill(table, emptyslot);
size = 0;
- threshold = (table.length / 2) / 4 * 3;
+ threshold = (table.length >>> 3) * 3;
for (int i = old.length - 2; i >= 0; i -= 2)
{
}
/**
- * Removes from the HashMap and returns the value which is mapped by the
- * supplied key. If the key maps to nothing, then the HashMap remains
- * unchanged, and <pre>null</pre> is returned. NOTE: Since the value
- * could also be null, you must use containsKey to see if you are
- * actually removing a mapping. Unlike normal maps, this tests for the
- * key with <code>entry == key</code> instead of
- * <code>entry == null ? key == null : entry.equals(key)</code>.
+ * Removes from the HashMap and returns the value which is mapped by
+ * the supplied key. If the key maps to nothing, then the HashMap
+ * remains unchanged, and <code>null</code> is returned.
+ *
+ * NOTE: Since the value could also be null, you must use
+ * containsKey to see if you are actually removing a mapping.
+ * Unlike normal maps, this tests for the key with <code>entry ==
+ * key</code> instead of <code>entry == null ? key == null :
+ * entry.equals(key)</code>.
*
* @param key the key used to locate the value to remove
* @return whatever the key mapped to, if present
// By requiring at least 2 key/value slots, and rehashing at 75%
// capacity, we guarantee that there will always be either an emptyslot
// or a tombstone somewhere in the table.
- int h = 2 * Math.abs(System.identityHashCode(key) % (table.length / 2));
+ int h = Math.abs(System.identityHashCode(key) % (table.length >> 1)) << 1;
int del = -1;
int save = h;
/**
* Removes from the backing Map the last element which was fetched
- * with the <pre>next()</pre> method.
+ * with the <code>next()</code> method.
+ *
* @throws ConcurrentModificationException if the Map was modified
* @throws IllegalStateException if called when there is no last element
*/
s.defaultReadObject();
int num = s.readInt();
- table = new Object[2 * Math.max(num * 2, DEFAULT_CAPACITY)];
+ table = new Object[Math.max(num << 1, DEFAULT_CAPACITY) << 1];
// Read key/value pairs.
while (--num >= 0)
put(s.readObject(), s.readObject());