it.unimi.dsi.fastutil.ints.IntIterators Java Examples

The following examples show how to use it.unimi.dsi.fastutil.ints.IntIterators. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IntervalTest.java    From database with GNU General Public License v2.0 6 votes vote down vote up
public void testSubsets() {
	for( int i = 0; i < 10; i++ )
		for( int j = i - 1; j < 10; j++ ) {
			Interval interval = j < i ? EMPTY_INTERVAL : Interval.valueOf( i, j );
			IntSortedSet set = toSortedSet( interval );
			assertEquals( set, interval );
			assertTrue( Arrays.equals( IntIterators.unwrap( set.iterator() ), IntIterators.unwrap( set.iterator() ) ) );
			assertEquals( new IntOpenHashSet( set ), interval );
			for( int k = j - 1; k <= i + 1; k++ ) {
				assertTrue( Arrays.equals( IntIterators.unwrap( set.iterator( k ) ), IntIterators.unwrap( set.iterator( k ) ) ) );
				assertEquals( set.headSet( k ), interval.headSet( k ) );
				assertEquals( set.tailSet( k ), interval.tailSet( k ) );
				for( int l = k; l <= i + 1; l++ )
					assertEquals( set.subSet( k, l ), interval.subSet( k, l ) );
			}
		}
}
 
Example #2
Source File: SparseRepresentation.java    From zetasketch with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an iterator over the values in the temporary buffer in sorted order, or {@code null} if
 * the temporary buffer is empty.
 */
@Nullable
private IntIterator bufferIterator() {
  // Create a sorted, deduped iterator over the values in the temporary buffer, merging the
  // values with the existing difference encoded data, if applicable.
  if (!buffer.isEmpty()) {
    int[] intArray = buffer.toIntArray();
    Arrays.sort(intArray);
    return IntIterators.wrap(intArray);
  }
  return null;
}
 
Example #3
Source File: MergedIntIteratorTest.java    From zetasketch with Apache License 2.0 5 votes vote down vote up
@Test
public void next_ReturnsValuesInSortedOrder() {
  IntIterator a = IntIterators.wrap(new int[] {1, 2, 4});
  IntIterator b = IntIterators.wrap(new int[] {2, 3, 4, 5, 6, 7});

  assertEquals(
      Arrays.asList(1, 2, 2, 3, 4, 4, 5, 6, 7), Lists.newArrayList(new MergedIntIterator(a, b)));
}
 
Example #4
Source File: NormalRepresentationTest.java    From zetasketch with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that the sparse precision is downgraded, even if no data conversion actually takes
 * place. This is important since we want the precision and sparse precision to match the lowest
 * seen values when the sketch is written to disk.
 */
@Test
public void addSparseValues_DowngradesSparsePrecision() {
  NormalRepresentation repr = create(10, 15);
  Encoding.Sparse sparseEncoding = new Encoding.Sparse(10, 13);
  repr = repr.addSparseValues(sparseEncoding, IntIterators.EMPTY_ITERATOR);

  assertThat(repr.state.sparsePrecision).isEqualTo(13);
}
 
Example #5
Source File: AbstractCODECPreferenceData.java    From RankSys with Mozilla Public License 2.0 5 votes vote down vote up
private static <Cx> IntIterator getIdx(Cx cidxs, int len, CODEC<Cx> x_codec) {
    if (len == 0) {
        return IntIterators.EMPTY_ITERATOR;
    }
    int[] idxs = new int[len];
    x_codec.dec(cidxs, idxs, 0, len);
    if (!x_codec.isIntegrated()) {
        atled(idxs, 0, len);
    }
    return new ArrayIntIterator(idxs);
}
 
Example #6
Source File: PermutedFrontCodedStringList.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public ObjectListIterator<CharSequence> listIterator( final int k ) { return new AbstractObjectListIterator<CharSequence>() {
		final IntListIterator i = IntIterators.fromTo( 0, frontCodedStringList.size() );
		
		public boolean hasNext() { return i.hasNext(); }
		public boolean hasPrevious() { return i.hasPrevious(); }
		public CharSequence next() { return frontCodedStringList.get( permutation[ i.nextInt() ] ); }
		public CharSequence previous() { return frontCodedStringList.get( permutation[ i.previousInt() ] ); }
		public int nextIndex() { return i.nextIndex(); }
		public int previousIndex() { return i.previousIndex(); }
	};
}
 
Example #7
Source File: Interval.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/** Returns an iterator over the integers in this interval larger than or equal to a given integer. 
 *
 * @param from the starting integer.
 * @return an integer iterator over the elements in this interval.
 */
public IntBidirectionalIterator iterator( final int from ) {
	if ( this == EMPTY_INTERVAL ) return IntIterators.EMPTY_ITERATOR;
	// Note that fromTo() does NOT include the last integer.
	final IntBidirectionalIterator i = IntIterators.fromTo( left, right + 1 );
	if ( from > left ) i.skip( Math.min( length(), from - left ) );
	return i;
}
 
Example #8
Source File: InMemoryHashAggregationBuilder.java    From presto with Apache License 2.0 4 votes vote down vote up
private IntIterator consecutiveGroupIds()
{
    return IntIterators.fromTo(0, groupByHash.getGroupCount());
}
 
Example #9
Source File: Interval.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/** Returns an iterator over the integers in this interval. 
 * 
 * @return an integer iterator over the elements in this interval.
 */
public IntBidirectionalIterator iterator() {
	if ( this == EMPTY_INTERVAL ) return IntIterators.EMPTY_ITERATOR;
	// Note that fromTo() does NOT include the last integer.
	return IntIterators.fromTo( left, right + 1 );
}