@Override protected LongOpenHashSet createSet() { return new LongOpenHashSet(); }
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 testRemoveAndResizeSimple() { set = new LongOpenHashSet(16); assertEquals(12, set.getThreshold()); set.addAll(range(11)); set.remove(5); set.add(11); set.add(12); // This one leads to resize set.add(13); LongArray expected = new LongArray(range(14)); expected.removeSorted(5); checkSet(set, expected); }
public void testRemoveAndResize() { int[] capacities = {16, 32, 64, 128, 256}; int maxVal = 100000; int attempts = 20; for (int capacity : capacities) { for (int attempt = 0; attempt < attempts; attempt++) { set = new LongOpenHashSet(capacity); int threshold = set.getThreshold(); LongArray values = generateRandomLongArray(capacity * 2, SORTED_UNIQUE, maxVal); int th1 = threshold / 2; set.addAll(values.subList(0, threshold)); assertEquals(threshold, set.getThreshold()); assertEquals(threshold, set.size()); checkSet(set, values.subList(0, threshold)); set.removeAll(values.subList(0, th1)); checkSet(set, values.subList(th1, threshold)); int th2 = threshold * 2; set.addAll(values.subList(threshold, th2)); checkSet(set, values.subList(th1, th2)); } } } }