ํ์ฌ IntMap ๊ตฌํ์ ์ต๋ ์ฉ๋์ ์ฝ 11425๊ฐ ํญ๋ชฉ์ ๋๋ค. 1.9.10๊ณผ 1.9.11-SNAPSHOT ๋ชจ๋์์ ํ ์คํธํ์ต๋๋ค. ๋ํ TestObject์ ๋ํ hashcode() ๋ฐ equals() ๋ฉ์๋๋ฅผ ์์ฑํ๋ ค๊ณ ์๋ํ์ต๋๋ค.
์ฌ์์ฐ์ผ๋ก ์๋์ ๋จ์ ํ ์คํธ๋ฅผ ์ฐธ์กฐํ์ญ์์ค.
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.RandomXS128;
import com.badlogic.gdx.utils.IntMap;
import org.junit.Assert;
import org.junit.Test;
public class IntMapTest {
<strong i="9">@Test</strong>
public void testLargeMap() {
final int totalEntries = 11427;
final float minX = -64000f;
final float minY = -38400f;
final float maxX = Math.abs(minX);
final float maxY = Math.abs(minY);
MathUtils.random = new RandomXS128(1024);
final IntMap<TestObject> intMap = new IntMap<TestObject>(totalEntries);
for(int i = 0; i < totalEntries; i++) {
final TestObject testObject = new TestObject();
testObject.x = MathUtils.random(minX, maxX);
testObject.y = MathUtils.random(minY, maxY);
intMap.put(testObject.getIndex(), testObject);
}
Assert.assertEquals(totalEntries, intMap.size);
}
private class TestObject {
float x, y;
public int getIndex() {
final int row = MathUtils.floor(y / 8f);
final int column = MathUtils.floor(x / 8f);
return (row * ((64000 / 8))) + column;
}
}
}
์ง๊ธ ์กฐ์ฌ ์ค์ ๋๋ค.
์ฌ๊ธฐ์๋ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ๋์ผํ ํค๋ฅผ Map์ ์ฝ์ ํ๋ฉด ์๋ ๊ฐ์ด ์ ๊ฐ์ผ๋ก ๋ฐ๋๊ณ ์๋ ๊ฐ์ด ๋ฐํ๋ฉ๋๋ค(JDK์ IntMap.put() ๋ฌธ์ ๋๋ Map.put() ์ฐธ์กฐ). ๊ทธ๋ฆฌ๊ณ ๊ทธ๊ฒ์ด ์ผ์ด๋๊ณ ์๋ ์ ๋ถ์ ๋๋ค. ํด๋น ํค๊ฐ ์ด๋ฏธ IntMap์ ์๊ณ 11424๊ฐ ์ค๋ณต ์์ด ์ฝ์ ๋ ๊ฒฝ์ฐ ํ ์คํธ๋ ํญ์ 3๊ฐ์ ํค(getIndex()์ ๊ฒฐ๊ณผ)๋ฅผ ์ฝ์ ํฉ๋๋ค. ์ธ๋ฑ์ค๊ฐ ๋ฐ๋ณต๋ ๋ ๋๋ฒ๊ทธ ์ธ์๋ฅผ ์ถ๊ฐํ์ต๋๋ค.
21094870 was the same as 21094870
-13869065 was the same as -13869065
-17368612 was the same as -17368612
expected:<11427> but was:<11424>
Expected :11427
Actual :11424
๊ฒฐ๊ณผ์ ์ผ๋ก IntMap์์ 3๊ฐ์ ์ค๋ณต ํญ๋ชฉ๊ณผ 3๊ฐ์ ํญ๋ชฉ์ด ์ ์ต๋๋ค. 11424๊ฐ ์ต๋๊ฐ์ด๋ฉด ๋ค์์ด ๋ถ๊ฐ๋ฅํฉ๋๋ค.
21094870 was the same as 21094870
-13869065 was the same as -13869065
-17368612 was the same as -17368612
expected:<12427> but was:<12424>
Expected :12427
Actual :12424
๊ทธ๋ฌ๋ ์ฐ๋ฆฌ๋ ์ค์ ๋ก ์ฒ ์ ํ๊ฒ ํ ์คํธ๋ Map ๊ตฌํ์์ 11424๊ฐ ์ด์์ ํญ๋ชฉ์ ์ป์ ์ ์์ต๋๋ค... 1์์ PR์ ์ํด ์ํํ ๋ง์ ํ ์คํธ ์ค ํ๋๋ 100,000 ๋๋ 1,000,000 ํญ๋ชฉ์ ๋ฃ์ libGDX ์ปฌ๋ ์ ์ ๋ฒค์น๋งํนํ๋ ๊ฒ์ด์์ต๋๋ค. ๊ทธ๋์ ์ ๋ 11,427์ ์ฒ๋ฆฌํ ์ ์๋ค๊ณ ๊ฝค ํ์ ํ์ต๋๋ค.
์ด ํ
์คํธ๋ 1.9.10์ ํด์ ๊ธฐ๋ฐ ์ปฌ๋ ์
์ ๋จ์ ์ ๋
ธ์ถํ๋ฉฐ 1.9.11์ ๋ํ PR์ด ์ค์ํ ๋ ๋ค๋ฅธ ์ด์ ์ธ ObjectMap, ObjectSet, IntMap, IntIntMap, IntFloatMap, LongMap, IdentityMap, OrderedMap ๋ฐ OrderedSet(๋ด๊ฐ ๋์ณค๋์? any?)๋ ๋ด๋ถ์ ์ผ๋ก MathUtils.random(2)
๋ฅผ ๊ฑฐ์ ํธ์ถํ์ง ์์ผ๋ฉฐ, ์ด๋ ์๋๋ RandomXS128 ๋๋ Random ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ์ฌ MathUtils์ ๋์ ์์ฑ ๋ฉ์๋์ ๋ํ ๊ฒฐ์ ๋ก ์ ํธ์ถ ์งํฉ์ ์๋ง์ผ๋ก ๋ง๋ญ๋๋ค. ์ฆ, TestObject์ ์ ๋ฌ๋ ๋ถ๋ ์์์ ์ 1.9.10, 1.9.11 ๋ฐ 1.9.10์์ ๋ค๋ฅด๋ฉฐ ๋ชจ๋ IntMap ํธ์ถ์ด ์ ๊ฑฐ๋์์ต๋๋ค(MathUtils์ ์ํด ์์ฑ๋ ๋ถ๋ ์์์ ๋ง ๊ธฐ๋ก). ์ฌ์ ํ ์ฉ๋ ์ ํ์ด ์์ผ๋ฉฐ ๊ด์ฐฐ๋ ๋์์ ์ฌ์ ํ โโ์์๋๊ณ ๋ฌธ์ํ๋ Map ๋์์ด์ง๋ง ์ ๊ณต๋ ๋์ ์คํธ๋ฆผ์ด libGDX 1.9.10์์ ๋ค๋ฅด๊ธฐ ๋๋ฌธ์ IntMap์ ์ค์ ํฌ๊ธฐ๋ ๋ค๋ฅผ ๊ฒ์
๋๋ค. (1.9.11์ 3 ๋์ ๋ ๊ฐ์ ๋ฐ๋ณต ๊ฐ์ด ์๋ ์ฝ๊ฐ ๋ค๋ฅผ ๋ฟ์ด์ง๋ง MathUtil
์ ์ ์ Random
IntMap ํธ์ถ๊ณผ ๊ฒฝ์ํ์ง ์๊ธฐ ๋๋ฌธ์ ํน์ ์ง์ ์ดํ์ ๋ชจ๋ ์ซ์๋ ๋ค๋ฆ
๋๋ค.
์กฐ์ฌํด์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค! ๊ฒ์ ๋ด์์ ๋ด ์ธ๋ฑ์ค๋ฅผ ๊ณ์ฐํ๋ ๋ฐฉ๋ฒ์ ๋ค์ ๊ฒํ ํ์ง๋ง ์ค๋ณต์ด ์์ด์ผ ํฉ๋๋ค. ๊ฒ์๊ณผ ๋จ์ ํ ์คํธ ๋ชจ๋์์ ํญ์ 11425๊ฐ์ ํญ๋ชฉ์ด ์์๋ ๊ฒ์ ์ฐ์ฐ์ด์์ ๊ฒ์ ๋๋ค. IntMap์์ ๋ฌด์์ด๋ ์ ํํ ์ง์ ํ๋ฉด ๋ฌธ์ ๋ฅผ ๋ค์ ์ด๊ฒ ์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ง๊ธ ์กฐ์ฌ ์ค์ ๋๋ค.