@Nullable private static LongList tryLcsForPermutation(LongList aseq, LongList bseq) { int sz = aseq.size(); LongOpenHashSet from = LongOpenHashSet.createFrom(aseq); if (sz != bseq.size() || sz != from.size() || !from.containsAll(bseq)) { return null; } return getLcsForPermutation(aseq, bseq); }
@Override protected LongOpenHashSet createSet() { return new LongOpenHashSet(); }
@Override protected List<LongOpenHashSet> createSets(LongList sortedUniqueList) { List<LongOpenHashSet> sets = new ArrayList<LongOpenHashSet>(); sets.add(LongOpenHashSet.createFrom(sortedUniqueList)); set = LongOpenHashSet.createForAdd(sortedUniqueList.size(), 0.5f); set.addAll(sortedUniqueList); sets.add(set); return sets; }
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)); } } } }
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 testCreateForAdd() { int minSize = 16, maxSize = 266; float[] loadFactors = {0.1f, 0.3f, 0.5f, 0.75f, 0.99f}; for (float loadFactor : loadFactors) { for (int size = minSize; size <= maxSize; size++) { set = LongOpenHashSet.createForAdd(size, loadFactor); int curThreshold = set.getThreshold(); assertTrue(set.getThreshold() + "<" + size + "; load factor = " + loadFactor, set.getThreshold() >= size); LongList expected = range(size); set.addAll(expected); checkSet(set, expected); assertEquals(curThreshold, set.getThreshold()); } } }
@Override protected LongOpenHashSet createSet(LongList sortedUniqueList) { return LongOpenHashSet.createFrom(sortedUniqueList); }
@Override protected LongOpenHashSet createSetWithCapacity(int capacity) { return LongOpenHashSet.createForAdd(capacity); }
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 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); } } } }