Java Code Examples for gnu.trove.map.hash.TLongObjectHashMap#put()

The following examples show how to use gnu.trove.map.hash.TLongObjectHashMap#put() . 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: CommitCanvasN5.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
private static void writeBlocksLabelMultisetType(
		final RandomAccessibleInterval<UnsignedLongType> canvas,
		final long[] blocks,
		final DatasetSpec datasetSpec,
		final BlockSpec blockSpec,
		final TLongObjectHashMap<BlockDiff> blockDiff) throws IOException {
	final RandomAccessibleInterval<LabelMultisetType> highestResolutionData = N5LabelMultisets.openLabelMultiset(datasetSpec.container, datasetSpec.dataset);
	for (final long blockId : blocks) {
		blockSpec.fromLinearIndex(blockId);
		final IntervalView<Pair<LabelMultisetType, UnsignedLongType>> backgroundWithCanvas = Views.interval(Views.pair(highestResolutionData, canvas), blockSpec.asInterval());
		final int numElements = (int) Intervals.numElements(backgroundWithCanvas);
		final byte[] byteData = LabelUtils.serializeLabelMultisetTypes(new BackgroundCanvasIterable(Views.flatIterable(backgroundWithCanvas)), numElements);
		final ByteArrayDataBlock dataBlock = new ByteArrayDataBlock(Intervals.dimensionsAsIntArray(backgroundWithCanvas), blockSpec.pos, byteData);
		datasetSpec.container.writeBlock(datasetSpec.dataset, datasetSpec.attributes, dataBlock);
		blockDiff.put(blockId, createBlockDiffFromCanvas(backgroundWithCanvas));
	}
}
 
Example 2
Source File: CommitCanvasN5.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
private static <I extends IntegerType<I> & NativeType<I>> void writeBlocksLabelIntegerType(
		final RandomAccessibleInterval<UnsignedLongType> canvas,
		final long[] blocks,
		final DatasetSpec datasetSpec,
		final BlockSpec blockSpec,
		final TLongObjectHashMap<BlockDiff> blockDiff) throws IOException {
	final RandomAccessibleInterval<I> highestResolutionData = N5Utils.open(datasetSpec.container, datasetSpec.dataset);
	final I i = Util.getTypeFromInterval(highestResolutionData).createVariable();
	for (final long blockId : blocks) {
		blockSpec.fromLinearIndex(blockId);
		final RandomAccessibleInterval<Pair<I, UnsignedLongType>> backgroundWithCanvas = Views.interval(Views.pair(highestResolutionData, canvas), blockSpec.asInterval());
		final RandomAccessibleInterval<I> mergedData = Converters.convert(backgroundWithCanvas, (s, t) -> pickFirstIfSecondIsInvalid(s.getA(), s.getB(), t), i.createVariable());
		N5Utils.saveBlock(mergedData, datasetSpec.container, datasetSpec.dataset, datasetSpec.attributes, blockSpec.pos);
		blockDiff.put(blockId, createBlockDiffFromCanvasIntegerType(Views.iterable(backgroundWithCanvas)));
	}
}
 
Example 3
Source File: CurrencyCache.java    From financisto with GNU General Public License v2.0 5 votes vote down vote up
public static synchronized void initialize(EntityManager em) {
       TLongObjectHashMap<Currency> currencies = new TLongObjectHashMap<Currency>();
	Query<Currency> q = em.createQuery(Currency.class);
	Cursor c = q.execute();
	try {
		while (c.moveToNext()) {
			Currency currency = EntityManager.loadFromCursor(c, Currency.class);
			currencies.put(currency.id, currency);
		}
	} finally {
		c.close();
	}
	CURRENCIES.putAll(currencies);
}
 
Example 4
Source File: CommitCanvasN5.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
private static <I extends IntegerType<I> & NativeType<I>> void downsampleAndWriteBlocksIntegerType(
		final long[] affectedBlocks,
		final N5Writer n5,
		final DatasetSpec previousDataset,
		final DatasetSpec targetDataset,
		final BlockSpec blockSpec,
		final Scale3D targetToPrevious,
		final int[] relativeFactors,
		final int level,
		final TLongObjectHashMap<BlockDiff> blockDiffsAt
) throws IOException {

	final RandomAccessibleInterval<I> previousData = N5Utils.open(n5, previousDataset.dataset);

	for (final long targetBlock : affectedBlocks)
	{
		blockSpec.fromLinearIndex(targetBlock);
		final double[] blockMinDouble = ArrayMath.asDoubleArray3(blockSpec.min);
		final double[] blockMaxDouble = ArrayMath.asDoubleArray3(ArrayMath.add3(blockSpec.max, 1));
		targetToPrevious.apply(blockMinDouble, blockMinDouble);
		targetToPrevious.apply(blockMaxDouble, blockMaxDouble);

		LOG.debug("level={}: blockMinDouble={} blockMaxDouble={}", level, blockMinDouble, blockMaxDouble);

		final long[] blockMin = ArrayMath.minOf3(ArrayMath.asLong3(ArrayMath.floor3(blockMinDouble, blockMinDouble)), previousDataset.dimensions);
		final long[] blockMax = ArrayMath.minOf3(ArrayMath.asLong3(ArrayMath.ceil3(blockMaxDouble, blockMaxDouble)), previousDataset.dimensions);
		final Interval targetInterval = new FinalInterval(blockSpec.min, blockSpec.max);
		final int[] size = Intervals.dimensionsAsIntArray(targetInterval);

		final long[] previousRelevantIntervalMin = blockMin.clone();
		final long[] previousRelevantIntervalMax = ArrayMath.add3(blockMax, -1);

		ArrayMath.divide3(blockMin, previousDataset.blockSize, blockMin);
		ArrayMath.divide3(blockMax, previousDataset.blockSize, blockMax);
		ArrayMath.add3(blockMax, -1, blockMax);
		ArrayMath.minOf3(blockMax, blockMin, blockMax);

		LOG.trace("Reading old access at position {} and size {}. ({} {})", blockSpec.pos, size, blockSpec.min, blockSpec.max);

		final BlockDiff blockDiff = downsampleIntegerTypeAndSerialize(
				n5,
				targetDataset.dataset,
				targetDataset.attributes,
				Views.interval(previousData, previousRelevantIntervalMin, previousRelevantIntervalMax),
				relativeFactors,
				size,
				targetInterval,
				blockSpec.pos);
		blockDiffsAt.put(targetBlock, blockDiff);
	}
}
 
Example 5
Source File: ChainingTSCPair.java    From monsoon with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public TsvChain(@NonNull DateTime initTs, @NonNull TimeSeriesValue initTsv) {
    final TLongObjectHashMap<TimeSeriesValue> tail = new TLongObjectHashMap<>();
    tail.put(initTs.getMillis(), initTsv);
    tailRefForAccess = new SoftReference<>(tail);
    tailRefForUpdate = new WeakReference<>(tail);
}