Search in sources :

Example 11 with IntIterator

use of it.unimi.dsi.fastutil.ints.IntIterator in project druid by druid-io.

the class MemoryOpenHashTableTest method pairSet.

/**
 * Returns a set of key, value pairs from the provided table. Uses the table's {@link MemoryOpenHashTable#bucketIterator()}
 * method.
 */
private static Set<ByteBufferPair> pairSet(final MemoryOpenHashTable table) {
    final Set<ByteBufferPair> retVal = new HashSet<>();
    final IntIterator bucketIterator = table.bucketIterator();
    while (bucketIterator.hasNext()) {
        final int bucket = bucketIterator.nextInt();
        final ByteBuffer entryBuffer = table.memory().getByteBuffer().duplicate();
        entryBuffer.position(table.bucketMemoryPosition(bucket));
        entryBuffer.limit(entryBuffer.position() + table.bucketSize());
        // Must copy since we're materializing, and the buffer will get reused.
        final ByteBuffer keyBuffer = ByteBuffer.allocate(table.keySize());
        final ByteBuffer keyDup = entryBuffer.duplicate();
        final int keyPosition = keyDup.position() + table.bucketKeyOffset();
        keyDup.position(keyPosition);
        keyDup.limit(keyPosition + table.keySize());
        keyBuffer.put(keyDup);
        keyBuffer.position(0);
        final ByteBuffer valueBuffer = ByteBuffer.allocate(table.valueSize());
        final ByteBuffer valueDup = entryBuffer.duplicate();
        final int valuePosition = valueDup.position() + table.bucketValueOffset();
        valueDup.position(valuePosition);
        valueDup.limit(valuePosition + table.valueSize());
        valueBuffer.put(valueDup);
        valueBuffer.position(0);
        retVal.add(new ByteBufferPair(keyBuffer, valueBuffer));
    }
    return retVal;
}
Also used : IntIterator(it.unimi.dsi.fastutil.ints.IntIterator) ByteBuffer(java.nio.ByteBuffer) HashSet(java.util.HashSet)

Example 12 with IntIterator

use of it.unimi.dsi.fastutil.ints.IntIterator in project druid by druid-io.

the class DictionaryEncodedColumnMerger method mergeBitmaps.

protected MutableBitmap mergeBitmaps(@Nullable List<IntBuffer> segmentRowNumConversions, BitmapFactory bmpFactory, IndexSeeker[] dictIdSeeker, int dictId) throws IOException {
    List<IntIterable> convertedInvertedIndexesToMerge = Lists.newArrayListWithCapacity(adapters.size());
    for (int j = 0; j < adapters.size(); ++j) {
        int seekedDictId = dictIdSeeker[j].seek(dictId);
        if (seekedDictId != IndexSeeker.NOT_EXIST) {
            IntIterable values;
            if (segmentRowNumConversions != null) {
                values = new ConvertingBitmapValues(adapters.get(j).getBitmapValues(dimensionName, seekedDictId), segmentRowNumConversions.get(j));
            } else {
                BitmapValues bitmapValues = adapters.get(j).getBitmapValues(dimensionName, seekedDictId);
                values = bitmapValues::iterator;
            }
            convertedInvertedIndexesToMerge.add(values);
        }
    }
    MutableBitmap mergedIndexes = bmpFactory.makeEmptyMutableBitmap();
    List<IntIterator> convertedInvertedIndexesIterators = new ArrayList<>(convertedInvertedIndexesToMerge.size());
    for (IntIterable convertedInvertedIndexes : convertedInvertedIndexesToMerge) {
        convertedInvertedIndexesIterators.add(convertedInvertedIndexes.iterator());
    }
    // Merge ascending index iterators into a single one, remove duplicates, and add to the mergedIndexes bitmap.
    // Merge is needed, because some compacting MutableBitmap implementations are very inefficient when bits are
    // added not in the ascending order.
    int prevRow = IndexMerger.INVALID_ROW;
    for (IntIterator mergeIt = IntIteratorUtils.mergeAscending(convertedInvertedIndexesIterators); mergeIt.hasNext(); ) {
        int row = mergeIt.nextInt();
        if (row != prevRow && row != IndexMerger.INVALID_ROW) {
            mergedIndexes.add(row);
        }
        prevRow = row;
    }
    if (dictId == 0 && firstDictionaryValue == null) {
        mergedIndexes.or(nullRowsBitmap);
    }
    bitmapWriter.write(bmpFactory.makeImmutableBitmap(mergedIndexes));
    return mergedIndexes;
}
Also used : IntIterator(it.unimi.dsi.fastutil.ints.IntIterator) MutableBitmap(org.apache.druid.collections.bitmap.MutableBitmap) ArrayList(java.util.ArrayList) BitmapValues(org.apache.druid.segment.data.BitmapValues) IntIterable(it.unimi.dsi.fastutil.ints.IntIterable)

Example 13 with IntIterator

use of it.unimi.dsi.fastutil.ints.IntIterator in project druid by druid-io.

the class MergeIntIteratorTest method testMergeEmptyIterators.

@Test(expected = NoSuchElementException.class)
public void testMergeEmptyIterators() {
    IntIterator it = IntIteratorUtils.mergeAscending(Arrays.asList(IntIterators.EMPTY_ITERATOR, IntIterators.EMPTY_ITERATOR));
    assertEmpty(it);
}
Also used : IntIterator(it.unimi.dsi.fastutil.ints.IntIterator) Test(org.junit.Test)

Example 14 with IntIterator

use of it.unimi.dsi.fastutil.ints.IntIterator in project Cloud9 by lintool.

the class AnchorText method write.

/**
 * Serializes an AnchorText object
 *
 * @param out
 *         Output Stream
 */
public void write(DataOutput out) throws IOException {
    out.writeByte(type);
    if (hasValidText()) {
        out.writeUTF(text);
    }
    if (hasValidDocumentList()) {
        out.writeInt(documentList.size());
        IntIterator iterator = documentList.iterator();
        while (iterator.hasNext()) {
            out.writeInt(iterator.next());
        }
    }
    if (hasValidWeight()) {
        out.writeFloat(weight);
    }
}
Also used : IntIterator(it.unimi.dsi.fastutil.ints.IntIterator)

Example 15 with IntIterator

use of it.unimi.dsi.fastutil.ints.IntIterator in project gradle by gradle.

the class IntSetSerializer method write.

@Override
public void write(Encoder encoder, IntSet value) throws Exception {
    encoder.writeInt(value.size());
    IntIterator iterator = value.iterator();
    while (iterator.hasNext()) {
        encoder.writeInt(iterator.nextInt());
    }
}
Also used : IntIterator(it.unimi.dsi.fastutil.ints.IntIterator)

Aggregations

IntIterator (it.unimi.dsi.fastutil.ints.IntIterator)31 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)4 IntOpenHashSet (it.unimi.dsi.fastutil.ints.IntOpenHashSet)3 Centroid (de.lmu.ifi.dbs.elki.math.linearalgebra.Centroid)2 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)2 BitmapBackedSelection (tech.tablesaw.selection.BitmapBackedSelection)2 Selection (tech.tablesaw.selection.Selection)2 PartitionKey (com.tencent.angel.PartitionKey)1 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)1 ClassLabel (de.lmu.ifi.dbs.elki.data.ClassLabel)1 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)1 Model (de.lmu.ifi.dbs.elki.data.model.Model)1 GeneratorSingleCluster (de.lmu.ifi.dbs.elki.data.synthetic.bymodel.GeneratorSingleCluster)1 LeafEntry (de.lmu.ifi.dbs.elki.index.tree.LeafEntry)1 XTreeDirectoryEntry (de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.xtree.XTreeDirectoryEntry)1 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)1 LongStatistic (de.lmu.ifi.dbs.elki.logging.statistics.LongStatistic)1 CovarianceMatrix (de.lmu.ifi.dbs.elki.math.linearalgebra.CovarianceMatrix)1 EigenvalueDecomposition (de.lmu.ifi.dbs.elki.math.linearalgebra.EigenvalueDecomposition)1