@Override public LongIterable get(LongArray... arrays) { LongArray copy = LongArray.copy(arrays[0]); copy.merge(arrays[1]); return copy; } }, unionGetter, true, SORTED_UNIQUE);
public void testUnionSortedSets() { int maxSize = 1000, attemptsCount = 30; WritableLongSet[] sets = new WritableLongSet[2]; LongArray[] arrays = new LongArray[2]; LongArray expected, actual; for (int attempt = 0; attempt < attemptsCount; attempt++) { for (int j = 0; j < 2; j++) { arrays[j] = generateRandomLongArray(maxSize, IntegersFixture.SortedStatus.SORTED_UNIQUE); sets[j] = (myRand.nextBoolean()) ? LongTreeSet.createFromSortedUnique(arrays[j]) : LongOpenHashSet.createFrom(arrays[j]); } expected = new LongArray(maxSize * 2); expected.addAll(arrays[0]); expected.merge(arrays[1]); actual = toSortedUnion(sets[0], sets[1]).toArray(); CHECK.order(expected, actual); } }
public void testRandom(int maxVal, int setSize, int listSize, int nAttempts) { LongArray toAdd = new LongArray(listSize); for (int attempt = 0; attempt < nAttempts; ++attempt) { if (attempt % 3 == 0) set = createSet(); LongArray expected = generateRandomLongArray(setSize, UNORDERED, maxVal); set.clear(); set.addAll(expected); expected.sortUnique(); checkSet(set, expected); toAdd.clear(); toAdd.addAll(generateRandomLongArray(listSize, SORTED_UNIQUE, maxVal)); for (LongIterator it: set) { toAdd.removeAllSorted(it.value()); } set.addAll(toAdd); LongArray expected2 = LongArray.copy(expected); expected2.merge(toAdd); checkSet(set, expected2); set.removeAll(toAdd); checkSet(set, expected); } }
public void testIntersectionUnionSets() { int attempts = 10, maxVal = Integer.MAX_VALUE, size = 1000; WritableLongSet[][] allSets = {{new LongTreeSet(), new LongOpenHashSet()}, {new LongTreeSet(), new LongOpenHashSet()}}; LongArray[] arrays = new LongArray[2]; LongArray expected, actual; for (int attempt = 0; attempt < attempts; attempt++) { for (WritableLongSet set0: allSets[0]) { for (WritableLongSet set1: allSets[1]) { WritableLongSet[] sets = {set0, set1}; for (int j = 0; j < 2; j++) { arrays[j] = generateRandomLongArray(size, IntegersFixture.SortedStatus.SORTED_UNIQUE, maxVal); sets[j].clear(); sets[j].addAll(arrays[j]); } expected = LongArray.copy(arrays[0]); expected.retain(arrays[1]); IntegersFixture.checkSet(toSortedIntersection(sets[0], sets[1]), expected); IntegersFixture.checkSet(intersection(sets[0], sets[1]), expected); expected = LongArray.copy(arrays[0]); expected.merge(arrays[1]); IntegersFixture.checkSet(union(sets[0], sets[1]), expected); } } } }
public void testRandom(int maxVal, int setSize, int listSize, int nAttempts) { set = new LongAmortizedSet(); LongArray toAdd = new LongArray(listSize); for (int attempt = 0; attempt < nAttempts; ++attempt) { if (attempt % 3 == 0) set = new LongAmortizedSet(); LongArray expected = generateRandomLongArray(setSize, UNORDERED, maxVal); set.clear(); set.addAll(expected); expected.sortUnique(); checkSet(set, expected); toAdd.clear(); toAdd.addAll(generateRandomLongArray(listSize, SORTED_UNIQUE, maxVal)); for (LongIterator it : set) { toAdd.removeAllSorted(it.value()); } set.addAll(toAdd); LongArray expected2 = LongArray.copy(expected); expected2.merge(toAdd); checkSet(set, expected2); set.removeAll(toAdd); set.coalesce(); LongArray notExpected = collectLists(map(LongFunctions.INC, expected), map(LongFunctions.DEC, expected)); notExpected.removeAll(expected); set.removeAll(notExpected); checkSet(set, expected); } }