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

The following examples show how to use gnu.trove.list.array.TLongArrayList#size() . 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: 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 2
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 3
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 4
Source File: RangeSplitter.java    From tikv-client-lib-java with Apache License 2.0 4 votes vote down vote up
public List<RegionTask> splitHandlesByRegion(long tableId, TLongArrayList handles) {
  // Max value for current index handle range
  ImmutableList.Builder<RegionTask> regionTasks = ImmutableList.builder();
  handles.sort();

  int startPos = 0;
  TableCodec.DecodeResult decodeResult = new TableCodec.DecodeResult();
  while (startPos < handles.size()) {
    long curHandle = handles.get(startPos);
    byte[] key = TableCodec.encodeRowKeyWithHandleBytes(tableId, curHandle);
    Pair<TiRegion, Metapb.Store> regionStorePair = regionManager.getRegionStorePairByKey(ByteString.copyFrom(key));
    byte[] endKey = regionStorePair.first.getEndKey().toByteArray();
    TableCodec.tryDecodeRowKey(tableId, endKey, decodeResult);
    if (decodeResult.status == Status.MIN) {
      throw new TiClientInternalException("EndKey is less than current rowKey");
    } else if (decodeResult.status == Status.MAX || decodeResult.status == Status.UNKNOWN_INF) {
      createTask(startPos, handles.size(), tableId, handles, regionStorePair, regionTasks);
      break;
    }

    // Region range is a close-open range
    // If region end key match exactly or slightly less than a handle,
    // that handle should be excluded from current region
    // If region end key is greater than the handle, that handle should be included
    long regionEndHandle = decodeResult.handle;
    int pos = handles.binarySearch(regionEndHandle, startPos, handles.size());

    if (pos < 0) {
      // not found in handles, pos is the next greater pos
      // [startPos, pos) all included
      pos = -(pos + 1);
    } else if (decodeResult.status == Status.GREATER) {
      // found handle and then further consider decode status
      // End key decode to a value v: regionEndHandle < v < regionEndHandle + 1
      // handle at pos included
      pos ++;
    }
    createTask(startPos, pos, tableId, handles, regionStorePair, regionTasks);
    // pos equals to start leads to an dead loop
    // startPos and its handle is used for searching region in PD.
    // The returning close-open range should at least include startPos's handle
    // so only if PD error and startPos is not included in current region then startPos == pos
    if (startPos >= pos) {
      throw new TiClientInternalException("searchKey is not included in region returned by PD");
    }
    startPos = pos;
  }
  return regionTasks.build();
}