java.util.TreeMap.compute()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(1.9k)|赞(0)|评价(0)|浏览(219)

本文整理了Java中java.util.TreeMap.compute()方法的一些代码示例,展示了TreeMap.compute()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TreeMap.compute()方法的具体详情如下:
包路径:java.util.TreeMap
类名称:TreeMap
方法名:compute

TreeMap.compute介绍

[英]Find the level down to which to assign all nodes BLACK. This is the last full' level of the complete binary tree produced by buildTree. The remaining nodes are colored RED. (This makes anice' set of color assignments wrt future insertions.) This level number is computed by finding the number of splits needed to reach the zeroeth node. (The answer is ~lg(N), but in any case must be computed by same quick O(lg(N)) loop.)
[中]查找要将所有节点指定为黑色的级别。这是buildTree生成的完整二叉树的最后一个“完整”级别。其余节点的颜色为红色。(这将为将来的插入创建一组“漂亮”的颜色指定。)通过查找到达zeroeth节点所需的拆分数来计算此级别数。(答案是~lg(N),但在任何情况下都必须由相同的快速O(lg(N))循环计算。)

代码示例

代码示例来源:origin: nlpie/biomedicus

public Builder addIdentifier(int identifier) {
 identifierToCount.compute(identifier, (id, count) -> {
  if (count == null) {
   count = 0;
  }
  return count + 1;
 });
 return this;
}

代码示例来源:origin: opencb/opencga

private void addVariant(Variant variant, String chromosome, long slicePos) {
  List<Variant> list;
  TreeMap<Long, List<Variant>> positionMap = bufferTree.compute(chromosome,
      (s, map) -> map == null ? new TreeMap<>(Long::compareTo) : map);
  list = positionMap.compute(slicePos, (pos, variants) -> variants == null ? new LinkedList<>() : variants);
  if (list.isEmpty()) {
    // New list, new slice
    numSlices++;
  }
  list.add(variant);
  if (currentChromosome == null) {
    // Set first chromosome
    currentChromosome = chromosome;
  }
}

代码示例来源:origin: BaseXdb/basex

/**
 * Adds a package to the specified map.
 * @param pkg package
 * @param map map
 */
private static void add(final Pkg pkg, final TreeMap<String, Pkg> map) {
 map.compute(pkg.id(), (k, v) -> v == null ? pkg : v.merge(pkg));
}

代码示例来源:origin: org.basex/basex

/**
 * Adds a package to the specified map.
 * @param pkg package
 * @param map map
 */
private static void add(final Pkg pkg, final TreeMap<String, Pkg> map) {
 map.compute(pkg.id(), (k, v) -> v == null ? pkg : v.merge(pkg));
}

相关文章

微信公众号

最新文章

更多