Java Code Examples for gnu.trove.list.array.TLongArrayList#toArray()

The following examples show how to use gnu.trove.list.array.TLongArrayList#toArray() . 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: Grids.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get all blocks/cells of a {@link CellGrid} that the real interval defined by {@code min} and {@code max}
 * intersects with, represented as linear indices.
 * @param min top-left corner of interval
 * @param max bottom-right corner of interval
 * @param cellGrid defines grid (block size/cell size)
 * @return linear indices of all cells/blocks that intersect with interval defined by {@code min}, {@code max}.
 */
public static long[] getIntersectingBlocks(
		final double[] min,
		final double[] max,
		final CellGrid cellGrid)
{
	final Interval relevantInterval = snapToGrid(min, max, cellGrid);
	final int[] blockSize = new int[cellGrid.numDimensions()];
	cellGrid.cellDimensions(blockSize);
	final TLongArrayList blockIndices = new TLongArrayList();
	net.imglib2.algorithm.util.Grids.forEachOffset(
			Intervals.minAsLongArray(relevantInterval),
			Intervals.maxAsLongArray(relevantInterval),
			blockSize,
			blockOffset -> blockIndices.add(posToIndex(cellGrid, blockOffset)));
	return blockIndices.toArray();
}
 
Example 2
Source File: Grids.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get all blocks/cells of a {@link CellGrid} that the real interval defined by {@code min} and {@code max}
 * intersects with, represented as linear indices.
 * @param min top-left corner of interval
 * @param max bottom-right corner of interval
 * @param cellGrid defines grid (block size/cell size)
 * @return linear indices of all cells/blocks that intersect with interval defined by {@code min}, {@code max}.
 */
public static long[] getIntersectingBlocks(
		final long[] min,
		final long[] max,
		final CellGrid cellGrid)
{
	final Interval relevantInterval = snapToGrid(min, max, cellGrid);
	final int[] blockSize = new int[cellGrid.numDimensions()];
	cellGrid.cellDimensions(blockSize);
	final TLongArrayList blockIndices = new TLongArrayList();
	net.imglib2.algorithm.util.Grids.forEachOffset(
			Intervals.minAsLongArray(relevantInterval),
			Intervals.maxAsLongArray(relevantInterval),
			blockSize,
			blockOffset -> blockIndices.add(posToIndex(cellGrid, blockOffset)));
	return blockIndices.toArray();
}
 
Example 3
Source File: IrregularTimeSeriesIndex.java    From powsybl-core with Mozilla Public License 2.0 6 votes vote down vote up
public static IrregularTimeSeriesIndex parseJson(JsonParser parser) {
    Objects.requireNonNull(parser);
    JsonToken token;
    try {
        TLongArrayList times = new TLongArrayList();
        while ((token = parser.nextToken()) != null) {
            if (token == JsonToken.VALUE_NUMBER_INT) {
                times.add(parser.getLongValue());
            } else if (token == JsonToken.END_ARRAY) {
                return new IrregularTimeSeriesIndex(times.toArray());
            }
        }
        throw new IllegalStateException("Should not happen");
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example 4
Source File: Position.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Position(Portfolio portfolio, String assetName, TIntArrayList quantity, TLongArrayList timeMillSec) {
	 this( portfolio,  assetName, quantity.toArray(),  timeMillSec.toArray());
}
 
Example 5
Source File: Position.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Position(Portfolio portfolio, String assetName, TDoubleArrayList price, TIntArrayList quantity, TLongArrayList timeMillSec) {
	this( portfolio,  assetName,  price.toArray(),  quantity.toArray(),  timeMillSec.toArray());
}
 
Example 6
Source File: Position.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Position(Portfolio portfolio, String assetName, TFloatArrayList price, int quantity, TLongArrayList priceTimeMillSec) {
	this( portfolio, assetName,  price.toArray(),  quantity,  priceTimeMillSec.toArray());
}
 
Example 7
Source File: Position.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Position(Portfolio portfolio, String assetName, TDoubleArrayList price, TLongArrayList priceTimeMillSec, TIntArrayList quantity, TLongArrayList quantityTimeMillSec) {
	this(portfolio, assetName, price.toArray(),  priceTimeMillSec.toArray(),  quantity.toArray(),  quantityTimeMillSec.toArray());
}
 
Example 8
Source File: Position.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Position(Portfolio portfolio, String assetName, TFloatArrayList price, TLongArrayList priceTimeMillSec, TIntArrayList quantity, TLongArrayList quantityTimeMillSec) {
	this( portfolio,  assetName,  price.toArray(),  priceTimeMillSec.toArray(),  quantity.toArray(),  quantityTimeMillSec.toArray());
}
 
Example 9
Source File: SSTableIndexIndex.java    From hadoop-sstable with Apache License 2.0 4 votes vote down vote up
/**
 * Create and write an index index based on the input Cassandra Index.db file. Read the Index.db and generate chunks
 * (splits) based on the configured chunk size.
 *
 * @param fileSystem Hadoop file system.
 * @param sstablePath SSTable Index.db.
 * @throws IOException
 */
public static void writeIndex(final FileSystem fileSystem, final Path sstablePath) throws IOException {

    final Configuration configuration = fileSystem.getConf();

    final long splitSize = configuration.getLong(HadoopSSTableConstants.HADOOP_SSTABLE_SPLIT_MB,
            HadoopSSTableConstants.DEFAULT_SPLIT_MB) * 1024 * 1024;

    final Closer closer = Closer.create();

    final Path outputPath = sstablePath.suffix(SSTABLE_INDEX_SUFFIX);
    final Path inProgressOutputPath = sstablePath.suffix(SSTABLE_INDEX_IN_PROGRESS_SUFFIX);

    boolean success = false;
    try {
        final FSDataOutputStream os = closer.register(fileSystem.create(inProgressOutputPath));

        final TLongArrayList splitOffsets = new TLongArrayList();
        long currentStart = 0;
        long currentEnd = 0;
        final IndexOffsetScanner index = closer.register(new IndexOffsetScanner(sstablePath, fileSystem));

        while (index.hasNext()) {
            // NOTE: This does not give an exact size of this split in bytes but a rough estimate.
            // This should be good enough since it's only used for sorting splits by size in hadoop land.
            while (currentEnd - currentStart < splitSize && index.hasNext()) {
                currentEnd = index.next();
                splitOffsets.add(currentEnd);
            }

            // Record the split
            final long[] offsets = splitOffsets.toArray();
            os.writeLong(offsets[0]); // Start
            os.writeLong(offsets[offsets.length - 1]); // End

            // Clear the offsets
            splitOffsets.clear();

            if (index.hasNext()) {
                currentStart = index.next();
                currentEnd = currentStart;
                splitOffsets.add(currentStart);
            }
        }

        success = true;
    } finally {
        closer.close();

        if (!success) {
            fileSystem.delete(inProgressOutputPath, false);
        } else {
            fileSystem.rename(inProgressOutputPath, outputPath);
        }
    }
}