162 |
// Need at least two slots, or hash() will break. |
// Need at least two slots, or hash() will break. |
163 |
if (max < 2) |
if (max < 2) |
164 |
max = 2; |
max = 2; |
165 |
table = new Object[2 * max]; |
table = new Object[max << 1]; |
166 |
Arrays.fill(table, emptyslot); |
Arrays.fill(table, emptyslot); |
167 |
threshold = max / 4 * 3; |
threshold = (max >> 2) * 3; |
168 |
} |
} |
169 |
|
|
170 |
/** |
/** |
176 |
*/ |
*/ |
177 |
public IdentityHashMap(Map m) |
public IdentityHashMap(Map m) |
178 |
{ |
{ |
179 |
this(Math.max(m.size() * 2, DEFAULT_CAPACITY)); |
this(Math.max(m.size() << 1, DEFAULT_CAPACITY)); |
180 |
putAll(m); |
putAll(m); |
181 |
} |
} |
182 |
|
|
487 |
Object[] old = table; |
Object[] old = table; |
488 |
// This isn't necessarily prime, but it is an odd number of key/value |
// This isn't necessarily prime, but it is an odd number of key/value |
489 |
// slots, which has a higher probability of fewer collisions. |
// slots, which has a higher probability of fewer collisions. |
490 |
table = new Object[old.length * 2 + 2]; |
table = new Object[old.length << 1 + 2]; |
491 |
Arrays.fill(table, emptyslot); |
Arrays.fill(table, emptyslot); |
492 |
size = 0; |
size = 0; |
493 |
threshold = (table.length / 2) / 4 * 3; |
threshold = (table.length >>> 3) * 3; |
494 |
|
|
495 |
for (int i = old.length - 2; i >= 0; i -= 2) |
for (int i = old.length - 2; i >= 0; i -= 2) |
496 |
{ |
{ |
642 |
// By requiring at least 2 key/value slots, and rehashing at 75% |
// By requiring at least 2 key/value slots, and rehashing at 75% |
643 |
// capacity, we guarantee that there will always be either an emptyslot |
// capacity, we guarantee that there will always be either an emptyslot |
644 |
// or a tombstone somewhere in the table. |
// or a tombstone somewhere in the table. |
645 |
int h = 2 * Math.abs(System.identityHashCode(key) % (table.length / 2)); |
int h = Math.abs(System.identityHashCode(key) % (table.length >> 1)) << 1; |
646 |
int del = -1; |
int del = -1; |
647 |
int save = h; |
int save = h; |
648 |
|
|
894 |
s.defaultReadObject(); |
s.defaultReadObject(); |
895 |
|
|
896 |
int num = s.readInt(); |
int num = s.readInt(); |
897 |
table = new Object[2 * Math.max(num * 2, DEFAULT_CAPACITY)]; |
table = new Object[Math.max(num << 1, DEFAULT_CAPACITY) << 1]; |
898 |
// Read key/value pairs. |
// Read key/value pairs. |
899 |
while (--num >= 0) |
while (--num >= 0) |
900 |
put(s.readObject(), s.readObject()); |
put(s.readObject(), s.readObject()); |