gnu.trove.list.TLongList Java Examples

The following examples show how to use gnu.trove.list.TLongList. 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: ToXdrTables.java    From monsoon with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Partition timestamps according to the blocks that they should be in.
 *
 * @param timestamps The complete set of timestamps. Must be unique and
 * ordered.
 * @return A list of timestamp partitions.
 */
private static List<TLongList> partitionTimestamps(TLongList timestamps) {
    if (timestamps.isEmpty()) return emptyList();
    final List<TLongList> partitions = new ArrayList<>();

    TLongList active = new TLongArrayList();
    final TLongIterator tsIter = timestamps.iterator();
    active.add(tsIter.next());

    while (tsIter.hasNext()) {
        final long next = tsIter.next();
        assert next > active.get(active.size() - 1);

        if (next - active.get(active.size() - 1) > Integer.MAX_VALUE || active.size() >= MAX_BLOCK_RECORDS) {
            partitions.add(active);
            active = new TLongArrayList();
        }
        active.add(next);
    }
    partitions.add(active);

    assert partitions.stream().mapToInt(TLongList::size).sum() == timestamps.size();
    return partitions;
}
 
Example #2
Source File: CachedGridEntry.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean populateChunk(World world) {
    MutableBlockPos blockPos = new MutableBlockPos();
    boolean generatedAnything = false;
    for (OreDepositDefinition definition : oreBlocks.keySet()) {
        TLongList blockIndexList = oreBlocks.get(definition);
        TLongSet generatedBlocks = new TLongHashSet();
        boolean generatedOreVein = false;
        for (int i = 0; i < blockIndexList.size(); i++) {
            long blockIndex = blockIndexList.get(i);
            int xyzValue = (int) (blockIndex >> 32);
            int blockX = (byte) xyzValue;
            int blockZ = (byte) (xyzValue >> 8);
            int blockY = (short) (xyzValue >> 16);
            int index = (int) blockIndex;
            blockPos.setPos(chunkX * 16 + blockX, blockY, chunkZ * 16 + blockZ);
            IBlockState currentState = world.getBlockState(blockPos);
            IBlockState newState;
            if (index == 0) {
                //it's primary ore block
                if (!definition.getGenerationPredicate().test(currentState, world, blockPos))
                    continue; //do not generate if predicate didn't match
                newState = definition.getBlockFiller().apply(currentState, world, blockPos, blockX, blockY, blockZ);
            } else {
                //it's populator-generated block with index
                VeinBufferPopulator populator = (VeinBufferPopulator) definition.getVeinPopulator();
                newState = populator.getBlockByIndex(world, blockPos, index - 1);
            }
            //set flags as 16 to avoid observer updates loading neighbour chunks
            world.setBlockState(blockPos, newState, 16);
            generatedBlocks.add(Block.getStateId(newState));
            generatedOreVein = true;
            generatedAnything = true;
        }
        if (generatedOreVein) {
            this.generatedBlocksSet.put(definition, generatedBlocks);
            this.generatedOres.add(definition);
        }
    }
    return generatedAnything;
}
 
Example #3
Source File: ToXdrTables.java    From monsoon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static TLongIntMap buildTimestampLookupTable(TLongList timestamps) {
    final TLongIntMap lookupTable = new TLongIntHashMap(timestamps.size(), 4, -1, -1);

    final TLongIterator iter = timestamps.iterator();
    for (int idx = 0; iter.hasNext(); ++idx)
        lookupTable.put(iter.next(), idx);

    return lookupTable;
}
 
Example #4
Source File: ToXdrTables.java    From monsoon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Build a lookup table that maps timestamps to their block index.
 *
 * @param partitions The timestamp partition table.
 * @return A lookup table, with the keys being any of the timestamps,
 * mapping to the index in the partitions list.
 */
private static TLongIntMap buildTimestampLookupTable(List<TLongList> partitions) {
    final TLongIntMap lookupTable = new TLongIntHashMap(100, 4, -1, -1);

    final ListIterator<TLongList> iter = partitions.listIterator();
    while (iter.hasNext()) {
        final int partitionIndex = iter.nextIndex();
        iter.next().forEach((ts) -> {
            lookupTable.put(ts, partitionIndex);
            return true;
        });
    }

    return lookupTable;
}
 
Example #5
Source File: ReadonlyTableFile.java    From monsoon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Collection<DateTime> getTimestamps() {
    final TLongList timestamps = body.map(RTFFileDataTables::getAllTimestamps).decodeOrThrow();
    final List<DateTime> result = new ArrayList<>(timestamps.size());
    timestamps
            .forEach(v -> {
                result.add(new DateTime(v, DateTimeZone.UTC));
                return true;
            });
    return result;
}
 
Example #6
Source File: RestrictPainting.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
private static <T, U> void restrictTo(
		final RandomAccessible<Pair<T, U>> source,
		final RandomAccessible<UnsignedLongType> mask,
		final Localizable seed,
		final Shape shape,
		final Predicate<T> backgroundFilter,
		final Predicate<U> canvasFilter)
{
	final int n = source.numDimensions();

	final RandomAccessible<Pair<Pair<T, U>, UnsignedLongType>> paired = Views.pair(source, mask);

	final TLongList[] coordinates = new TLongList[n];
	for (int d = 0; d < n; ++d)
	{
		coordinates[d] = new TLongArrayList();
		coordinates[d].add(seed.getLongPosition(d));
	}

	final RandomAccessible<Neighborhood<Pair<Pair<T, U>, UnsignedLongType>>> neighborhood       = shape
			.neighborhoodsRandomAccessible(
			paired);
	final RandomAccess<Neighborhood<Pair<Pair<T, U>, UnsignedLongType>>>     neighborhoodAccess = neighborhood
			.randomAccess();

	final RandomAccess<UnsignedLongType> targetAccess = mask.randomAccess();
	targetAccess.setPosition(seed);
	targetAccess.get().set(1);

	final UnsignedLongType zero = new UnsignedLongType(0);
	final UnsignedLongType one  = new UnsignedLongType(1);
	final UnsignedLongType two  = new UnsignedLongType(2);

	for (int i = 0; i < coordinates[0].size(); ++i)
	{
		for (int d = 0; d < n; ++d)
		{
			neighborhoodAccess.setPosition(coordinates[d].get(i), d);
		}

		final Cursor<Pair<Pair<T, U>, UnsignedLongType>> neighborhoodCursor = neighborhoodAccess.get().cursor();

		while (neighborhoodCursor.hasNext())
		{
			final Pair<Pair<T, U>, UnsignedLongType> p                   = neighborhoodCursor.next();
			final UnsignedLongType                   m                   = p.getB();
			final Pair<T, U>                         backgroundAndCanvas = p.getA();
			if (m.valueEquals(zero) && canvasFilter.test(backgroundAndCanvas.getB()))
			{
				// If background is same as at seed, mark mask with two
				// (==not active), else with one (==active).
				m.set(backgroundFilter.test(backgroundAndCanvas.getA()) ? two : one);
				for (int d = 0; d < n; ++d)
				{
					coordinates[d].add(neighborhoodCursor.getLongPosition(d));
				}
			}

		}

		if (i > CLEANUP_THRESHOLD)
		{
			for (int d = 0; d < coordinates.length; ++d)
			{
				final TLongList c = coordinates[d];
				coordinates[d] = c.subList(i, c.size());
			}
			i = 0;
		}

	}
}
 
Example #7
Source File: MapUtils.java    From SkyBot with GNU Affero General Public License v3.0 4 votes vote down vote up
public static TLongList newLongList() {
    return new TSynchronizedLongList(new TLongArrayList(), new Object());
}
 
Example #8
Source File: ToXdrTables.java    From monsoon with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public BlockBuilder(@NonNull TLongList timestamps, @NonNull Context ctx) {
    this.timestamps = timestamps;
    this.lookupTable = buildTimestampLookupTable(this.timestamps);
    this.ctx = ctx;
    this.tablesBuilder = new TablesBuilder(this.ctx, this.timestamps.size());
}
 
Example #9
Source File: RTFFileDataTables.java    From monsoon with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public TLongList getAllTimestamps() {
    return blocks.map(block -> block.getTimestamps(), false, true, false).stream()
            .collect(TLongArrayList::new, TLongList::add, TLongList::addAll);
}
 
Example #10
Source File: TmpFileBasedColumnMajorTSData.java    From monsoon with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public MetricValuesMap(TLongList timestamps, Group groupData, MetricName metric) {
    entrySet = new MetricValuesEntrySet(timestamps, groupData, metric);
}
 
Example #11
Source File: TmpFileBasedColumnMajorTSData.java    From monsoon with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Iterator<TimestampedMetric> iterator(TLongList timestamps, MetricName metricName) {
    final Metric m = metrics.get(metricName);
    if (m == null) return emptyIterator();
    return m.iterator(timestamps);
}
 
Example #12
Source File: TmpFileBasedColumnMajorTSData.java    From monsoon with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Iterator<TimestampedMetric> iterator(TLongList timestamps) {
    final TLongIterator timestampIter = timestamps.iterator();
    return Iterators.transform(
            iterator(),
            metric -> new TimestampedMetric(new DateTime(timestampIter.next(), DateTimeZone.UTC), metric));
}