public void mergeWith(SetDigest other) { hll.mergeWith(other.hll); LongBidirectionalIterator iterator = other.minhash.keySet().iterator(); while (iterator.hasNext()) { long key = iterator.nextLong(); int count = minhash.get(key) + other.minhash.get(key); minhash.put(key, Shorts.saturatedCast(count)); } while (minhash.size() > maxHashes) { minhash.remove(minhash.lastLongKey()); } }
@Test public void testArrayCtor() { LongSortedSet set = new LongSortedArraySet(new long[]{2, 5, 6}); testSetSimple(set); LongBidirectionalIterator iter = set.iterator(); assertTrue(iter.hasNext()); assertEquals(2, iter.nextLong()); assertTrue(iter.hasPrevious()); assertEquals(2, iter.previousLong()); assertFalse(iter.hasPrevious()); }
@Override public long nextLong() { return i.nextLong(); } @Override
@Test public void testEmptySet() { LongSortedArraySet set = emptySet(); assertTrue(set.isEmpty()); assertEquals(0, set.size()); LongBidirectionalIterator iter = set.iterator(); assertNotNull(iter); assertFalse(iter.hasNext()); assertFalse(iter.hasPrevious()); assertFalse(set.contains(42)); assertFalse(set.contains(Long.valueOf(42))); }
@Test public void testSubsetIterator() { LongSortedSet set = LongUtils.packedSet(1L, 3L, 5L, 10L); LongSortedSet subset = set.subSet(3L, 6L); assertThat(subset, hasSize(2)); assertThat(subset, contains(3L, 5L)); LongBidirectionalIterator iter = subset.iterator(); assertThat(iter.hasPrevious(), equalTo(false)); try { iter.previousLong(); fail("previousLong should fail"); } catch (NoSuchElementException e) { /* expected */ } }
@Override public boolean hasNext() { return i.hasNext(); } @Override
@Override public boolean hasPrevious() { return i.hasPrevious(); } @Override
@Override public long previousLong() { return i.previousLong(); } }
/** * {@inheritDoc} * * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override default Long previous() { return LongBidirectionalIterator.super.previous(); } }
/** * {@inheritDoc} * * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override default Long next() { return LongBidirectionalIterator.super.next(); } /**
@Test public void testTailIter() { long[] data = {0, 42, 5, 2, 6, 1, 7}; LongSortedSet set = new LongSortedArraySet(data); LongBidirectionalIterator iter = set.iterator(2); assertTrue(iter.hasNext()); assertTrue(iter.hasPrevious()); assertEquals(5, iter.nextLong()); iter = set.iterator(2); assertEquals(2, iter.previousLong()); iter = set.iterator(-5); assertFalse(iter.hasPrevious()); iter = set.iterator(100); assertFalse(iter.hasNext()); iter = set.iterator(3); assertEquals(5, iter.nextLong()); iter = set.iterator(3); assertEquals(2, iter.previousLong()); }
@Override public LongBidirectionalIterator iterator(long from) { LongBidirectionalIterator i = iterator(); if (compare(element, from) <= 0) i.nextLong(); return i; } @Override
@Test public void testEmptySetSubset() { LongSortedArraySet set = emptySet(); LongSortedSet sset = set.headSet(50); assertTrue(sset.isEmpty()); assertEquals(0, sset.size()); assertFalse(set.iterator().hasNext()); assertFalse(set.iterator().hasPrevious()); assertFalse(set.contains(42)); assertFalse(set.contains(Long.valueOf(42))); }
/** * Moves back for the given number of elements. * * <p> * The effect of this call is exactly the same as that of calling * {@link #previous()} for {@code n} times (possibly stopping if * {@link #hasPrevious()} becomes false). * * @param n * the number of elements to skip back. * @return the number of elements actually skipped. * @see #previous() */ @Override default int back(final int n) { int i = n; while (i-- != 0 && hasPrevious()) previousLong(); return n - i - 1; } /** {@inheritDoc} */
/** * Run a battery of tests on a standard set. Used to test a variety of * construction scenarios with less code duplication. * * @param set The set {2, 5, 6}. */ private void testSetSimple(LongSortedSet set) { assertFalse(set.isEmpty()); assertEquals(3, set.size()); assertEquals(2, set.firstLong()); assertEquals(6, set.lastLong()); assertEquals(Long.valueOf(2), set.first()); assertEquals(Long.valueOf(6), set.last()); assertTrue(set.contains(2)); assertTrue(set.contains(5)); assertTrue(set.contains(6)); assertFalse(set.contains(0)); assertFalse(set.contains(42)); assertFalse(set.iterator().hasPrevious()); long[] items = LongIterators.unwrap(set.iterator()); assertEquals(2, items[0]); assertEquals(5, items[1]); assertEquals(6, items[2]); }
/** * {@inheritDoc} * * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override default Long previous() { return Long.valueOf(previousLong()); } /**
public void mergeWith(SetDigest other) { hll.mergeWith(other.hll); LongBidirectionalIterator iterator = other.minhash.keySet().iterator(); while (iterator.hasNext()) { long key = iterator.nextLong(); int count = minhash.get(key) + other.minhash.get(key); minhash.put(key, Shorts.saturatedCast(count)); } while (minhash.size() > maxHashes) { minhash.remove(minhash.lastLongKey()); } }
it = s0.iterator(); documentIterator = AndDocumentIterator.getInstance( indexIterator, additionalIterator ); for( int j = s0.size(); j-- != 0; ) if ( it.nextLong() != documentIterator.nextDocument() ) throw new AssertionError(); for( int j = s2.size(); j-- != 0; ) if ( it.nextLong() != documentIterator.nextDocument() ) throw new AssertionError();
public void mergeWith(SetDigest other) { hll.mergeWith(other.hll); LongBidirectionalIterator iterator = other.minhash.keySet().iterator(); while (iterator.hasNext()) { long key = iterator.nextLong(); int count = minhash.get(key) + other.minhash.get(key); minhash.put(key, Shorts.saturatedCast(count)); } while (minhash.size() > maxHashes) { minhash.remove(minhash.lastLongKey()); } }