Search in sources :

Example 1 with IntListIterator

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;
}
Also used : IntListIterator(it.unimi.dsi.fastutil.ints.IntListIterator) Lifespan(com.facebook.presto.execution.Lifespan)

Example 2 with IntListIterator

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());
}
Also used : IntListIterator(it.unimi.dsi.fastutil.ints.IntListIterator) Test(org.junit.Test)

Example 3 with IntListIterator

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());
// }
}
Also used : IntListIterator(it.unimi.dsi.fastutil.ints.IntListIterator)

Example 4 with IntListIterator

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());
}
Also used : IntListIterator(it.unimi.dsi.fastutil.ints.IntListIterator) Test(org.junit.Test)

Example 5 with IntListIterator

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);
}
Also used : Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) IntListIterator(it.unimi.dsi.fastutil.ints.IntListIterator) ArrayDBIDs(de.lmu.ifi.dbs.elki.database.ids.ArrayDBIDs) ArrayModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs) DBIDs(de.lmu.ifi.dbs.elki.database.ids.DBIDs) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap) DBIDArrayIter(de.lmu.ifi.dbs.elki.database.ids.DBIDArrayIter) Clustering(de.lmu.ifi.dbs.elki.data.Clustering) Int2IntOpenHashMap(it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap) ClusterModel(de.lmu.ifi.dbs.elki.data.model.ClusterModel) ArrayModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs) ArrayDBIDs(de.lmu.ifi.dbs.elki.database.ids.ArrayDBIDs) Int2IntMap(it.unimi.dsi.fastutil.ints.Int2IntMap) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)

Aggregations

IntListIterator (it.unimi.dsi.fastutil.ints.IntListIterator)6 Int2ObjectMap (it.unimi.dsi.fastutil.ints.Int2ObjectMap)2 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)2 Test (org.junit.Test)2 Lifespan (com.facebook.presto.execution.Lifespan)1 BucketNodeMap (com.facebook.presto.execution.scheduler.BucketNodeMap)1 InternalNode (com.facebook.presto.metadata.InternalNode)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 Clustering (de.lmu.ifi.dbs.elki.data.Clustering)1 ClusterModel (de.lmu.ifi.dbs.elki.data.model.ClusterModel)1 ArrayDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayDBIDs)1 ArrayModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs)1 DBIDArrayIter (de.lmu.ifi.dbs.elki.database.ids.DBIDArrayIter)1 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)1 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)1 Int2IntMap (it.unimi.dsi.fastutil.ints.Int2IntMap)1 Int2IntOpenHashMap (it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1