@Override public void testHashCode() { int attemptsCount = 10, shuffleCount = 10; int sizeMax = 600, step = 50; for (int attempt = 0; attempt < attemptsCount; attempt++) { for (int size = step; size < sizeMax; size += step) { LongArray keys = generateRandomLongArray(size, SORTED_UNIQUE); IntArray values = generateRandomIntArray(keys.size(), UNORDERED); int expectedHash = 0; for (int i = 0; i < size; i++) { expectedHash += IntegersUtils.hash(keys.get(i)) + (new Integer(values.get(i))).hashCode(); } for (WritableLongObjMap<Integer> map0 : createObjMapsFromLists(keys, values.toList())) { assertEquals(expectedHash, map0.hashCode()); } IntArray indices = new IntArray(IntProgression.range(size)); for (int i = 0; i < shuffleCount; i++) { map = createMap(); map.putAll(keys.get(indices), values.get(indices)); assertEquals(expectedHash, map.hashCode()); indices.shuffle(myRand); } } } } }
@Override public void testHashCode() { int attemptsCount = 10, shuffleCount = 10; int sizeMax = 600, step = 50; for (int attempt = 0; attempt < attemptsCount; attempt++) { for (int mSize = step; mSize < sizeMax; mSize += step) { LongArray keys = generateRandomLongArray(mSize, SORTED_UNIQUE); int size = keys.size(); IntArray values = generateRandomIntArray(size, UNORDERED); int expectedHash = 0; for (int i = 0; i < size; i++) { expectedHash += IntegersUtils.hash(keys.get(i)) + IntegersUtils.hash(values.get(i)); } for (T map0 : createMapsFromLists(keys, values)) { assertEquals(expectedHash, map0.hashCode()); } IntArray indices = new IntArray(IntProgression.range(size)); for (int i = 0; i < shuffleCount; i++) { map = createMap(); map.putAll(keys.get(indices), values.get(indices)); assertEquals(expectedHash, map.hashCode()); indices.shuffle(myRand); } } } }
@Override protected List<LongIntListMap> createMapsFromLists(LongList keys, IntList values) { IntArray indices = new IntArray(IntProgression.range(keys.size())); indices.shuffle(myRand); LongIntListMap createdMap = new LongIntListMap(); for (LongIntIterator it : LongIntIterators.pair(keys.get(indices), values.get(indices))) { createdMap.add(it.left(), it.right()); } final LongArray keys0 = new LongArray(keys); final IntArray values0 = new IntArray(values); IntegersUtils.quicksort(keys.size(), LongFunctions.comparator(keys0), new IntIntProcedure() { @Override public void invoke(int a, int b) { keys0.swap(a, b); values0.swap(a, b); } }); return Arrays.asList(new LongIntListMap(keys0, values0), createdMap); }
public void testHashCode() { int attemptsCount = 10, shuffleCount = 10; int sizeMax = 600, step = 50; for (int attempt = 0; attempt < attemptsCount; attempt++) { for (int size = step; size < sizeMax; size += step) { LongArray array = generateRandomLongArray(size, SORTED_UNIQUE); int expectedHash = 0; for (LongIterator it : array) { expectedHash += IntegersUtils.hash(it.value()); } for (T set0 : createSets(array)) { assertEquals(expectedHash, set0.hashCode()); } if (isSortedSet()) return; IntArray indices = new IntArray(IntProgression.range(size)); for (int i = 0; i < shuffleCount; i++) { for (T set : createSets(array.get(indices))) { assertEquals(expectedHash, set.hashCode()); indices.shuffle(myRand); } } } } }