Java Code Examples for java.util.NavigableMap#lastKey()

The following examples show how to use java.util.NavigableMap#lastKey() . 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: DebugStorageRangeAt.java    From besu with Apache License 2.0 6 votes vote down vote up
private JsonRpcSuccessResponse extractStorageAt(
    final JsonRpcRequestContext requestContext,
    final Address accountAddress,
    final Hash startKey,
    final int limit,
    final MutableWorldState worldState) {
  final Account account = worldState.get(accountAddress);
  final NavigableMap<Bytes32, AccountStorageEntry> entries =
      account.storageEntriesFrom(startKey, limit + 1);

  Bytes32 nextKey = null;
  if (entries.size() == limit + 1) {
    nextKey = entries.lastKey();
    entries.remove(nextKey);
  }
  return new JsonRpcSuccessResponse(
      requestContext.getRequest().getId(),
      new DebugStorageRangeAtResult(entries, nextKey, shortValues));
}
 
Example 2
Source File: BeaconBlocksByRangeMessageHandler.java    From teku with Apache License 2.0 6 votes vote down vote up
private SafeFuture<?> sendMatchingBlocks(
    final BeaconBlocksByRangeRequestMessage message,
    final ResponseCallback<SignedBeaconBlock> callback) {
  final UnsignedLong count = min(maxRequestSize, message.getCount());
  final UnsignedLong endSlot =
      message.getStartSlot().plus(message.getStep().times(count)).minus(ONE);

  final UnsignedLong headBlockSlot =
      combinedChainDataClient.getBestBlock().map(SignedBeaconBlock::getSlot).orElse(ZERO);
  final NavigableMap<UnsignedLong, Bytes32> hotRoots;
  if (combinedChainDataClient.isFinalized(endSlot)) {
    // All blocks are finalized so skip scanning the protoarray
    hotRoots = new TreeMap<>();
  } else {
    hotRoots =
        combinedChainDataClient.getAncestorRoots(
            message.getStartSlot(), message.getStep(), count);
  }
  // Don't send anything past the last slot found in protoarray to ensure blocks are consistent
  // If we didn't find any blocks in protoarray, every block in the range must be finalized
  // so we don't need to worry about inconsistent blocks
  final UnsignedLong headSlot = hotRoots.isEmpty() ? headBlockSlot : hotRoots.lastKey();
  return sendNextBlock(
      new RequestState(
          message.getStartSlot(), message.getStep(), count, headSlot, hotRoots, callback));
}
 
Example 3
Source File: NdTreeMapTest.java    From amodeus with GNU General Public License v2.0 5 votes vote down vote up
public void testSimple1() {
    final int n = 10;
    NdTreeMap<String> ndTreeMap = //
            new NdTreeMap<>(Tensors.vector(0, 0), Tensors.vector(1, 1), n, 26);
    for (int c = 0; c < 400; ++c)
        ndTreeMap.add(RandomVariate.of(UniformDistribution.unit(), 2), "s" + c);
    Tensor flatten = Flatten.of(ndTreeMap.binSize());
    assertEquals(Total.of(flatten), RealScalar.of(400));
    NavigableMap<Tensor, Long> map = Tally.sorted(flatten);
    Tensor last = map.lastKey();
    assertEquals(last, RealScalar.of(n));
}
 
Example 4
Source File: AlfrescoImapFolder.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns UIDNEXT value of the folder.
 * 
 * @return UIDNEXT value.
 */
@Override
public long getUidNext()
{
    NavigableMap<Long, FileInfo> search = getFolderStatus().search; 
    return search.isEmpty() ? 1 : search.lastKey() + 1;
}
 
Example 5
Source File: ScanResults.java    From ambry with Apache License 2.0 5 votes vote down vote up
/**
 * Given a reference time in milliseconds return the corresponding valid data size per log segment map by aggregating
 * all buckets whose end time is less than or equal to the reference time.
 * @param referenceTimeInMS the reference time in ms until which deletes and expiration are relevant
 * @return a {@link Pair} whose first element is the end time of the last bucket that was aggregated and whose second
 * element is the requested valid data size per log segment {@link NavigableMap}.
 */
Pair<Long, NavigableMap<String, Long>> getValidSizePerLogSegment(Long referenceTimeInMS) {
  NavigableMap<String, Long> validSizePerLogSegment = new TreeMap<>(logSegmentBuckets.firstEntry().getValue());
  NavigableMap<Long, NavigableMap<String, Long>> subMap =
      logSegmentBuckets.subMap(logSegmentBuckets.firstKey(), false, referenceTimeInMS, true);
  for (Map.Entry<Long, NavigableMap<String, Long>> bucket : subMap.entrySet()) {
    for (Map.Entry<String, Long> bucketEntry : bucket.getValue().entrySet()) {
      updateMapHelper(validSizePerLogSegment, bucketEntry.getKey(), bucketEntry.getValue());
    }
  }
  Long lastReferenceBucketTimeInMs = subMap.isEmpty() ? logSegmentBuckets.firstKey() : subMap.lastKey();
  return new Pair<>(lastReferenceBucketTimeInMs, validSizePerLogSegment);
}
 
Example 6
Source File: IsmReaderImpl.java    From beam with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the record for the last key having this iterators key prefix. Last is defined as the
 * largest key with the same key prefix when comparing key's byte representations using an
 * unsigned lexicographical byte order.
 *
 * <p>Null is returned if the prefix is not present within this file.
 */
@Override
public WindowedValue<IsmRecord<V>> getLast() throws IOException {
  RandomAccessData keyBytes = new RandomAccessData();
  int shardId = coder.encodeAndHash(keyComponents, keyBytes);

  Optional<SeekableByteChannel> inChannel =
      initializeFooterAndShardIndex(Optional.<SeekableByteChannel>absent(), readCounter);

  // Key is not stored here
  if (!shardIdToShardMap.containsKey(shardId) || !bloomFilterMightContain(keyBytes)) {
    return null;
  }

  inChannel = initializeForKeyedRead(shardId, inChannel, readCounter);
  closeIfPresent(inChannel);

  final NavigableMap<RandomAccessData, IsmShardKey> indexInShard = indexPerShard.get(shardId);
  RandomAccessData end = keyBytes.increment();
  final IsmShardKey cacheEntry = indexInShard.floorEntry(end).getValue();

  NavigableMap<RandomAccessData, WindowedValue<IsmRecord<V>>> block;
  try (Closeable readerCloser = IsmReader.setSideInputReadContext(readCounter)) {
    block = fetch(cacheEntry);
  }

  RandomAccessData lastKey = block.lastKey();

  // If the requested key is greater than the last key within the block, then it
  // does not exist.
  if (RandomAccessData.UNSIGNED_LEXICOGRAPHICAL_COMPARATOR.compare(keyBytes, lastKey) > 0) {
    return null;
  }

  Entry<RandomAccessData, WindowedValue<IsmRecord<V>>> rval = block.floorEntry(end);

  // If the prefix matches completely then we can return
  if (RandomAccessData.UNSIGNED_LEXICOGRAPHICAL_COMPARATOR.commonPrefixLength(
          keyBytes, rval.getKey())
      == keyBytes.size()) {
    return rval.getValue();
  }
  return null;
}