use of it.unimi.dsi.fastutil.ints.IntListIterator in project presto by prestodb.
the class FixedLifespanScheduler method schedule.
public SettableFuture schedule(SourceScheduler scheduler) {
// Return a new future even if newDriverGroupReady has not finished.
// Returning the same SettableFuture instance could lead to ListenableFuture retaining too many listener objects.
checkState(initialScheduled);
List<Lifespan> recentlyCompletedDriverGroups;
synchronized (this) {
recentlyCompletedDriverGroups = ImmutableList.copyOf(this.recentlyCompletelyExecutedDriverGroups);
this.recentlyCompletelyExecutedDriverGroups.clear();
newDriverGroupReady = SettableFuture.create();
}
for (Lifespan driverGroup : recentlyCompletedDriverGroups) {
IntListIterator driverGroupsIterator = nodeToDriverGroupsMap.get(driverGroupToNodeMap.get(driverGroup.getId()));
if (!driverGroupsIterator.hasNext()) {
continue;
}
int driverGroupId = driverGroupsIterator.nextInt();
scheduler.startLifespan(Lifespan.driverGroup(driverGroupId), partitionHandles.get(driverGroupId));
}
return newDriverGroupReady;
}
use of it.unimi.dsi.fastutil.ints.IntListIterator in project druid by druid-io.
the class IntIteratorUtilsTest method testSkip.
@Test
public void testSkip() {
Assert.assertEquals(0, IntIteratorUtils.skip(IntIterators.EMPTY_ITERATOR, 5));
Assert.assertEquals(0, IntIteratorUtils.skip(IntIterators.EMPTY_ITERATOR, 0));
IntListIterator it = IntIterators.fromTo(0, 10);
Assert.assertEquals(3, IntIteratorUtils.skip(it, 3));
Assert.assertEquals(3, it.nextInt());
Assert.assertEquals(6, IntIteratorUtils.skip(it, 100));
Assert.assertEquals(0, IntIteratorUtils.skip(it, 100));
Assert.assertFalse(it.hasNext());
}
use of it.unimi.dsi.fastutil.ints.IntListIterator in project Glowstone by GlowstoneMC.
the class ChunkSection method writeToBuf.
/**
* Writes this chunk section to the given ByteBuf.
*
* @param buf The buffer to write to.
* @param skylight True if skylight should be included.
* @throws IllegalStateException If this chunk section {@linkplain #isEmpty() is empty}
*/
public void writeToBuf(ByteBuf buf, boolean skylight) throws IllegalStateException {
if (this.isEmpty()) {
throw new IllegalStateException("Can't write empty sections");
}
// Bit per value -> varies
buf.writeByte(data.getBitsPerValue());
if (palette != null) {
// Palette size
ByteBufUtils.writeVarInt(buf, palette.size());
// Foreach loops can't be used due to autoboxing
IntListIterator itr = palette.iterator();
while (itr.hasNext()) {
// The palette entry
ByteBufUtils.writeVarInt(buf, itr.nextInt());
}
}
long[] backing = data.getBacking();
ByteBufUtils.writeVarInt(buf, backing.length);
buf.ensureWritable((backing.length << 3) + blockLight.byteSize() + (skylight ? skyLight.byteSize() : 0));
for (long value : backing) {
buf.writeLong(value);
}
// Palette
// Palette length
ByteBufUtils.writeVarInt(buf, 1);
// Palette data (AIR)
ByteBufUtils.writeVarInt(buf, 0);
// Section data (4096 indices of 4-bit, 64 bit longs -> 256 empty longs)
// Data size
ByteBufUtils.writeVarInt(buf, 256);
// 256 longs is 2048 bytes
buf.writeBytes(new byte[2048]);
// buf.writeByte(data.getBitsPerValue()); // Bit per value -> varies
// if (palette == null) {
// ByteBufUtils.writeVarInt(buf, 0); // Palette size -> 0 -> Use the global palette
// } else {
// ByteBufUtils.writeVarInt(buf, palette.size()); // Palette size
// // Foreach loops can't be used due to autoboxing
// IntListIterator itr = palette.iterator();
// while (itr.hasNext()) {
// ByteBufUtils.writeVarInt(buf, itr.nextInt()); // The palette entry
// }
// }
// long[] backing = data.getBacking();
// ByteBufUtils.writeVarInt(buf, backing.length);
// buf.ensureWritable((backing.length << 3) + blockLight.byteSize() + (skylight ? skyLight
// .byteSize() : 0));
// for (long value : backing) {
// buf.writeLong(value);
// }
// buf.writeBytes(blockLight.getRawData());
// if (skylight) {
// buf.writeBytes(skyLight.getRawData());
// }
}
use of it.unimi.dsi.fastutil.ints.IntListIterator in project druid by druid-io.
the class IntIteratorUtilsTest method testSkip.
@Test
public void testSkip() {
assertEquals(0, skip(IntIterators.EMPTY_ITERATOR, 5));
assertEquals(0, skip(IntIterators.EMPTY_ITERATOR, 0));
IntListIterator it = IntIterators.fromTo(0, 10);
assertEquals(3, skip(it, 3));
assertEquals(3, it.nextInt());
assertEquals(6, skip(it, 100));
assertEquals(0, skip(it, 100));
assertFalse(it.hasNext());
}
use of it.unimi.dsi.fastutil.ints.IntListIterator in project elki by elki-project.
the class ExternalClustering method attachToRelation.
/**
* Build a clustering from the file result.
*
* @param database Database
* @param r Result to attach to
* @param assignment Cluster assignment
* @param name Name
*/
private void attachToRelation(Database database, Relation<?> r, IntArrayList assignment, ArrayList<String> name) {
DBIDs ids = r.getDBIDs();
if (!(ids instanceof ArrayDBIDs)) {
throw new AbortException("External clusterings can only be used with static DBIDs.");
}
Int2IntOpenHashMap sizes = new Int2IntOpenHashMap();
for (IntListIterator it = assignment.iterator(); it.hasNext(); ) {
sizes.addTo(it.nextInt(), 1);
}
Int2ObjectOpenHashMap<ArrayModifiableDBIDs> cids = new Int2ObjectOpenHashMap<>(sizes.size());
for (ObjectIterator<Int2IntMap.Entry> it = sizes.int2IntEntrySet().fastIterator(); it.hasNext(); ) {
Int2IntMap.Entry entry = it.next();
cids.put(entry.getIntKey(), DBIDUtil.newArray(entry.getIntValue()));
}
{
DBIDArrayIter it = ((ArrayDBIDs) ids).iter();
for (int i = 0; i < assignment.size(); i++) {
cids.get(assignment.getInt(i)).add(it.seek(i));
}
}
String nam = FormatUtil.format(name, " ");
String snam = nam.toLowerCase().replace(' ', '-');
Clustering<ClusterModel> result = new Clustering<>(nam, snam);
for (ObjectIterator<Int2ObjectMap.Entry<ArrayModifiableDBIDs>> it = cids.int2ObjectEntrySet().fastIterator(); it.hasNext(); ) {
Int2ObjectMap.Entry<ArrayModifiableDBIDs> entry = it.next();
boolean noise = entry.getIntKey() < 0;
result.addToplevelCluster(new Cluster<>(entry.getValue(), noise, ClusterModel.CLUSTER));
}
database.getHierarchy().add(r, result);
}
Aggregations