gnu.trove.list.array.TLongArrayList Java Examples

The following examples show how to use gnu.trove.list.array.TLongArrayList. 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: FloodFillTransformedPlane.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
private void addIfInside(
		final boolean isRelevant,
		final long fillLabel,
		final long pixelLabel,
		final TLongArrayList labelCoordinates,
		final TDoubleArrayList worldCoordinates,
		final long lx,
		final long ly,
		final long lz,
		final double wx,
		final double wy,
		final double wz,
		final double zMinInclusive,
		final double zMaxInclusive)
{
	if (isRelevant && fillLabel != pixelLabel && wz >= zMinInclusive && wz <= zMaxInclusive)
	{
		if (wx > minX && wx < maxX && wy > minY && wy < maxY)
		{
			labelCoordinates.add(lx);
			labelCoordinates.add(ly);
			labelCoordinates.add(lz);

			worldCoordinates.add(wx);
			worldCoordinates.add(wy);
			worldCoordinates.add(wz);
		}
	}
}
 
Example #5
Source File: Util.java    From PE-HFT-Java with GNU General Public License v3.0 5 votes vote down vote up
public static TIntArrayList getHours(TLongArrayList t){
		TIntArrayList hour= new TIntArrayList(t.size());
	
	for(int i=0; i<t.size();i++)
		hour.add( (int) (t.getQuick(i)/3600000L) );
	
	return hour;
}
 
Example #6
Source File: Util.java    From PE-HFT-Java with GNU General Public License v3.0 5 votes vote down vote up
public static TIntArrayList getMillisecFromHourStart(TLongArrayList t){
		TIntArrayList hour= new TIntArrayList(t.size());
	
	for(int i=0; i<t.size();i++)
		hour.add( (int) (t.getQuick(i)%3600000L) );
	
	return hour;
}
 
Example #7
Source File: RangeSplitter.java    From tikv-client-lib-java with Apache License 2.0 5 votes vote down vote up
private void createTask(
    int startPos,
    int endPos,
    long tableId,
    TLongArrayList handles,
    Pair<TiRegion, Metapb.Store> regionStorePair,
    ImmutableList.Builder<RegionTask> regionTasks) {
  TiRegion region = regionStorePair.first;
  Store store = regionStorePair.second;
  List<KeyRange> newKeyRanges = new ArrayList<>(endPos - startPos + 1);
  long startHandle = handles.get(startPos);
  long endHandle = startHandle;
  for (int i = startPos + 1; i < endPos; i++) {
    long curHandle = handles.get(i);
    if (endHandle + 1 == curHandle) {
      endHandle = curHandle;
    } else {
      newKeyRanges.add(KeyRangeUtils.makeCoprocRangeWithHandle(
          tableId,
          startHandle,
          endHandle + 1));
      startHandle = curHandle;
      endHandle = startHandle;
    }
  }
  newKeyRanges.add(KeyRangeUtils.makeCoprocRangeWithHandle(tableId, startHandle, endHandle + 1));
  regionTasks.add(new RegionTask(region, store, newKeyRanges));
}
 
Example #8
Source File: IndexScanIterator.java    From tikv-client-lib-java with Apache License 2.0 5 votes vote down vote up
@Override
public boolean hasNext() {
  try {
    if (rowIterator == null) {
      TiSession session = snapshot.getSession();
      while (handleIterator.hasNext()) {
        TLongArrayList handles = feedBatch();
        batchCount++;
        completionService.submit(() -> {
          List<RegionTask> tasks = RangeSplitter
              .newSplitter(session.getRegionManager())
              .splitHandlesByRegion(dagReq.getTableInfo().getId(), handles);
          return CoprocessIterator.getRowIterator(dagReq, tasks, session);
        });
      }
      while (batchCount > 0) {
        rowIterator = completionService.take().get();
        batchCount--;

        if (rowIterator.hasNext()) {
          return true;
        }
      }
    }
    if (rowIterator == null) {
      return false;
    }
  } catch (Exception e) {
    throw new TiClientInternalException("Error reading rows from handle", e);
  }
  return rowIterator.hasNext();
}
 
Example #9
Source File: IndexScanIterator.java    From tikv-client-lib-java with Apache License 2.0 5 votes vote down vote up
private TLongArrayList feedBatch() {
  TLongArrayList handles = new TLongArrayList(512);
  while (handleIterator.hasNext()) {
    handles.add(handleIterator.next());
    if (batchSize <= handles.size()) {
      break;
    }
  }
  return handles;
}
 
Example #10
Source File: FloodFillTransformedCylinder3D.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
private void addIfInside(
		final TLongArrayList labelCoordinates,
		final TDoubleArrayList worldCoordinates,
		final long lx,
		final long ly,
		final long lz,
		final double wx,
		final double wy,
		final double wz,
		final double cx,
		final double cy,
		final double zMinInclusive,
		final double zMaxInclusive)
{
	if (wz >= zMinInclusive && wz <= zMaxInclusive)
	{
		final double dx = wx - cx;
		final double dy = wy - cy;
		if (dx * dx * radiusYSquared + dy * dy * radiusXSquared <= radiusXSquaredRadiusYSquared)
		{
			labelCoordinates.add(lx);
			labelCoordinates.add(ly);
			labelCoordinates.add(lz);

			worldCoordinates.add(wx);
			worldCoordinates.add(wy);
			worldCoordinates.add(wz);
		}
	}
}
 
Example #11
Source File: PortfolioOptimizer.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public void addConstraint(LazyMetric lazy, String constraintType, TDoubleArrayList expectedValues, TLongArrayList timeMilliSec) {
	addConstraint( lazy, constraintType,  expectedValues.toArray(), timeMilliSec.toArray());
}
 
Example #12
Source File: DateTimeUtil.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public static TLongArrayList toPOSIXTimeWithDeltaTLongArrayList(String[] timeString) {
	return new TLongArrayList( toPOSIXTimeWithDelta(timeString));
}
 
Example #13
Source File: DateTimeUtil.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public static String[] POSIXTimeToDateStr(TLongArrayList timesMills, DateFormat dateFormat) {
	return  POSIXTimeToDateStr(timesMills.toArray(), dateFormat);
}
 
Example #14
Source File: DateTimeUtil.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public static TLongArrayList toPOSIXTimeTLongArrayList(String[] timeString) {
	return new  TLongArrayList( toPOSIXTime(timeString) );
}
 
Example #15
Source File: DateTimeUtil.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public static TLongArrayList toPOSIXTimeTLongArrayList(String timeString) {
	return new TLongArrayList( toPOSIXTime(timeString));
}
 
Example #16
Source File: DateTimeUtil.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public static String[] POSIXTimeToDateStr(TLongArrayList timesMills) {
	return POSIXTimeToDateStr( timesMills.toArray());
}
 
Example #17
Source File: DateTimeUtil.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public static TLongArrayList  toPOSIXTimeWithDeltaTLongArrayList(String timeString) {
	return new  TLongArrayList( toPOSIXTimeWithDelta( timeString));
}
 
Example #18
Source File: ForecastedValues.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Metric setIndexForecastedSkewness( TDoubleArrayList value, TLongArrayList time) {
	return setIndexForecastedSkewness( value.toArray()	,  time.toArray());
}
 
Example #19
Source File: ForecastedValues.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Metric setIndexForecastedVariance( TDoubleArrayList value, TLongArrayList time) {
	return  setIndexForecastedVariance( value.toArray()	,  time.toArray());
}
 
Example #20
Source File: ForecastedValues.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Metric setSymbolForecastedCumulant4(String symbol, TDoubleArrayList value, TLongArrayList time) {
	return  setSymbolForecastedCumulant4(symbol, value.toArray()	,  time.toArray());
}
 
Example #21
Source File: ForecastedValues.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Metric setSymbolForecastedCumulant3(String symbol, TDoubleArrayList value, TLongArrayList time) {
	return  setSymbolForecastedCumulant3(symbol, value.toArray()	,  time.toArray());
}
 
Example #22
Source File: ForecastedValues.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Metric setSymbolForecastedCumulant2(String symbol, TDoubleArrayList value, TLongArrayList time) {
	return  setSymbolForecastedCumulant2(symbol, value.toArray()	,  time.toArray());
}
 
Example #23
Source File: ForecastedValues.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Metric setSymbolForecastedCumulant1(String symbol, TDoubleArrayList value, TLongArrayList time) {
	return  setSymbolForecastedCumulant1(symbol, value.toArray()	,  time.toArray());
}
 
Example #24
Source File: ForecastedValues.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Metric setSymbolForecastedKurtosis(String symbol, TDoubleArrayList value, TLongArrayList time) {
	return setSymbolForecastedKurtosis(symbol, value.toArray()	,  time.toArray());
}
 
Example #25
Source File: ForecastedValues.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Metric setSymbolForecastedSkewness(String symbol, TDoubleArrayList value, TLongArrayList time) {
	return  setSymbolForecastedSkewness( symbol,  value.toArray(),  time.toArray());
}
 
Example #26
Source File: ForecastedValues.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Metric setSymbolForecastedVariance(String symbol, TDoubleArrayList value, TLongArrayList time) {
	return  setSymbolForecastedVariance( symbol,  value.toArray(),  time.toArray()) ;
}
 
Example #27
Source File: ForecastedValues.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Metric setSymbolForecastedBeta(String symbol, TDoubleArrayList value, TLongArrayList time) {
	return  setSymbolForecastedBeta( symbol,  value,  time);
}
 
Example #28
Source File: ForecastedValues.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Metric setSymbolForecastedExpReturn(String symbol, TDoubleArrayList value, TLongArrayList time) {
	return  setSymbolForecastedExpReturn( symbol,  value.toArray(),  time.toArray());
}
 
Example #29
Source File: ForecastedValues.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Metric setForecastTimeStep(TDoubleArrayList value, TLongArrayList time) {
	return setForecastTimeStep( value.toArray(), time.toArray());
}
 
Example #30
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);
        }
    }
}