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;
}
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;
}
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);
}
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);
}
}
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());
}
}
Aggregations