mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-09-21 03:51:08 +02:00
Correctly resize integer map (#2422)
This commit is contained in:
parent
260cb22f53
commit
88d8c2eb1d
@ -76,8 +76,7 @@ public class IntegerMap<T> {
|
|||||||
|
|
||||||
// Fast calculation of the new size.
|
// Fast calculation of the new size.
|
||||||
// See IntMath#ceilingPowerOfTwo in newer guava versions.
|
// See IntMath#ceilingPowerOfTwo in newer guava versions.
|
||||||
int newLength = IntegerMath.nextPowerOfTwo(key);
|
int newLength = IntegerMath.nextPowerOfTwo(key + 1);
|
||||||
|
|
||||||
this.array = Arrays.copyOf(array, newLength);
|
this.array = Arrays.copyOf(array, newLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.comphenix.protocol.collections;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.utility.IntegerMath;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
class IntegerMapTest {
|
||||||
|
@Test
|
||||||
|
public void testNextPower() {
|
||||||
|
assertEquals(128, IntegerMath.nextPowerOfTwo(127));
|
||||||
|
assertEquals(128, IntegerMath.nextPowerOfTwo(128));
|
||||||
|
assertEquals(256, IntegerMath.nextPowerOfTwo(129));
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testCapacityIncrement() {
|
||||||
|
IntegerMap<Boolean> map = new IntegerMap<>();
|
||||||
|
for (int i = 0; i < 512; i++) {
|
||||||
|
map.put(i, false);
|
||||||
|
}
|
||||||
|
assertEquals(map.size(), 512);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user