Hash-based containers now expose ensureCapacity()

This commit is contained in:
Sebastiano Vigna 2022-10-12 14:45:38 +02:00
parent ac10cae36e
commit 85bb33b1bf
3 changed files with 16 additions and 2 deletions

View file

@ -1,3 +1,7 @@
8.5.11
- Hash-based containers now expose ensureCapacity().
8.5.10
- Really fixed overflow bug in BigArrays.ensureOffsetLength(). Thanks

View file

@ -504,7 +504,12 @@ public class OPEN_HASH_MAP KEY_VALUE_GENERIC extends ABSTRACT_MAP KEY_VALUE_GENE
return containsNullKey ? size - 1 : size;
}
private void ensureCapacity(final int capacity) {
/** Ensures that this map can hold a certain number of keys without rehashing.
*
* @param capacity a number of keys; there will be no rehashing unless
* the map {@linkplain #size() size} exceeds this number.
*/
public void ensureCapacity(final int capacity) {
final int needed = arraySize(capacity, f);
if (needed > n) rehash(needed);
}

View file

@ -756,7 +756,12 @@ public class OPEN_HASH_SET KEY_GENERIC extends ABSTRACT_SET KEY_GENERIC implemen
return containsNull ? size - 1 : size;
}
private void ensureCapacity(final int capacity) {
/** Ensures that this set can hold a certain number of elements without rehashing.
*
* @param capacity a number of elements; there will be no rehashing unless
* the set {@linkplain #size() size} exceeds this number.
*/
public void ensureCapacity(final int capacity) {
final int needed = arraySize(capacity, f);
if (needed > n) rehash(needed);
}