当前位置: 首页>>代码示例>>Java>>正文


Java Range.intersection方法代码示例

本文整理汇总了Java中com.google.common.collect.Range.intersection方法的典型用法代码示例。如果您正苦于以下问题:Java Range.intersection方法的具体用法?Java Range.intersection怎么用?Java Range.intersection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.collect.Range的用法示例。


在下文中一共展示了Range.intersection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getEndpointByteMap

import com.google.common.collect.Range; //导入方法依赖的package包/类
/**
 * For a given FileWork, calculate how many bytes are available on each on node endpoint
 *
 * @param work the FileWork to calculate endpoint bytes for
 * @throws IOException
 */
public EndpointByteMap getEndpointByteMap(FileWork work) throws IOException {
  Stopwatch watch = Stopwatch.createStarted();



  ImmutableRangeMap<Long,BlockLocation> blockMap = getBlockMap(work.getStatus());
  EndpointByteMapImpl endpointByteMap = new EndpointByteMapImpl();
  long start = work.getStart();
  long end = start + work.getLength();
  Range<Long> rowGroupRange = Range.closedOpen(start, end);

  // Find submap of ranges that intersect with the rowGroup
  ImmutableRangeMap<Long,BlockLocation> subRangeMap = blockMap.subRangeMap(rowGroupRange);

  // Iterate through each block in this submap and get the host for the block location
  for (Map.Entry<Range<Long>,BlockLocation> block : subRangeMap.asMapOfRanges().entrySet()) {
    String[] hosts;
    Range<Long> blockRange = block.getKey();
    try {
      hosts = block.getValue().getHosts();
    } catch (IOException ioe) {
      throw new RuntimeException("Failed to get hosts for block location", ioe);
    }
    Range<Long> intersection = rowGroupRange.intersection(blockRange);
    long bytes = intersection.upperEndpoint() - intersection.lowerEndpoint();

    // For each host in the current block location, add the intersecting bytes to the corresponding endpoint
    for (String host : hosts) {
      NodeEndpoint endpoint = getNodeEndpoint(host);
      if (endpoint != null) {
        endpointByteMap.add(endpoint, bytes);
      } else {
        logger.debug("Failure finding SabotNode running on host {}.  Skipping affinity to that host.", host);
      }
    }
  }

  logger.debug("FileWork group ({},{}) max bytes {}", work.getStatus().getPath(), work.getStart(), endpointByteMap.getMaxBytes());

  logger.debug("Took {} ms to set endpoint bytes", watch.stop().elapsed(TimeUnit.MILLISECONDS));
  return endpointByteMap;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:49,代码来源:BlockMapBuilder.java


注:本文中的com.google.common.collect.Range.intersection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。