com.google.common.collect.MinMaxPriorityQueue.removeFirst()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(68)

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

MinMaxPriorityQueue.removeFirst介绍

[英]Removes and returns the least element of this queue.
[中]

代码示例

代码示例来源:origin: apache/hive

@Override
 public void processFinal() {
  while (!outputs.isEmpty()) {
   String row = outputs.removeFirst();
   digest.update(row.getBytes());
   printDirect(row);
  }
  printDirect(new String(Base64.encodeBase64(digest.digest())));
  digest.reset();
 }
}

代码示例来源:origin: apache/hive

@Override
 public void processFinal() {
  while (!outputs.isEmpty()) {
   printDirect(outputs.removeFirst());
  }
 }
}

代码示例来源:origin: apache/ignite

/**
   * This method is called after all the word entries have been processed. It writes the accumulated
   * statistics to the job output file.
   *
   * @param ctx The job context.
   * @throws IOException If failed.
   * @throws InterruptedException If failed.
   */
  @Override protected void cleanup(Context ctx) throws IOException, InterruptedException {
    IntWritable i = new IntWritable();
    Text txt = new Text();
    // iterate in desc order
    while (!q.isEmpty()) {
      Entry<Integer, String> e = q.removeFirst();
      i.set(e.getKey());
      txt.set(e.getValue());
      ctx.write(txt, i);
    }
  }
}

代码示例来源:origin: org.apache.hive/hive-common

@Override
 public void processFinal() {
  while (!outputs.isEmpty()) {
   String row = outputs.removeFirst();
   digest.update(row.getBytes());
   printDirect(row);
  }
  printDirect(new String(Base64.encodeBase64(digest.digest())));
  digest.reset();
 }
}

代码示例来源:origin: org.apache.hive/hive-common

@Override
 public void processFinal() {
  while (!outputs.isEmpty()) {
   printDirect(outputs.removeFirst());
  }
 }
}

代码示例来源:origin: griddynamics/jagger

private List<MethodProfile> getHotSpots(int maxSpots, Comparator<MethodStatistics> comparator) {
  List<MethodProfile> result = Lists.newArrayList();
  MinMaxPriorityQueue<MethodStatistics> hotSpots = MinMaxPriorityQueue
      .orderedBy(comparator)
      .maximumSize(maxSpots)
      .create(graph.getVertices());
  int queueSize = hotSpots.size();
  for (int i = 0; i < queueSize; i++) {
    result.add(assembleProfile(hotSpots.removeFirst()));
  }
  return result;
}

代码示例来源:origin: caskdata/cdap

/**
 * Balance the assignment by spreading it across all handlers evenly.
 *
 * @param handlerQueue The priority queue for tracking number of resources assigned to a given handler.
 * @param assigner The assigner for changing the assignment.
 * @param maxDiff The maximum differences between the handlers that has the most resources assigned vs the one with
 *                the least resources assigned.
 */
private <T> void balance(MinMaxPriorityQueue<HandlerSize<T>> handlerQueue,
             ResourceAssigner<T> assigner, int maxDiff) {
 HandlerSize<T> minHandler = handlerQueue.peekFirst();
 HandlerSize<T> maxHandler = handlerQueue.peekLast();
 // Move assignment from the handler that has the most assigned partition replica to the least one, until the
 // differences is within the desired range.
 Multimap<T, PartitionReplica> assignments = assigner.get();
 while (maxHandler.getSize() - minHandler.getSize() > maxDiff) {
  PartitionReplica partitionReplica = assignments.get(maxHandler.getHandler()).iterator().next();
  // Remove min and max from the queue, and perform the reassignment.
  handlerQueue.removeFirst();
  handlerQueue.removeLast();
  assigner.set(minHandler.getHandler(), partitionReplica);
  // After assignment, the corresponding size should get updated, hence put it back to the queue for next iteration.
  handlerQueue.add(minHandler);
  handlerQueue.add(maxHandler);
  minHandler = handlerQueue.peekFirst();
  maxHandler = handlerQueue.peekLast();
 }
}

代码示例来源:origin: co.cask.cdap/cdap-common

/**
 * Balance the assignment by spreading it across all handlers evenly.
 *
 * @param handlerQueue The priority queue for tracking number of resources assigned to a given handler.
 * @param assigner The assigner for changing the assignment.
 * @param maxDiff The maximum differences between the handlers that has the most resources assigned vs the one with
 *                the least resources assigned.
 */
private <T> void balance(MinMaxPriorityQueue<HandlerSize<T>> handlerQueue,
             ResourceAssigner<T> assigner, int maxDiff) {
 HandlerSize<T> minHandler = handlerQueue.peekFirst();
 HandlerSize<T> maxHandler = handlerQueue.peekLast();
 // Move assignment from the handler that has the most assigned partition replica to the least one, until the
 // differences is within the desired range.
 Multimap<T, PartitionReplica> assignments = assigner.get();
 while (maxHandler.getSize() - minHandler.getSize() > maxDiff) {
  PartitionReplica partitionReplica = assignments.get(maxHandler.getHandler()).iterator().next();
  // Remove min and max from the queue, and perform the reassignment.
  handlerQueue.removeFirst();
  handlerQueue.removeLast();
  assigner.set(minHandler.getHandler(), partitionReplica);
  // After assignment, the corresponding size should get updated, hence put it back to the queue for next iteration.
  handlerQueue.add(minHandler);
  handlerQueue.add(maxHandler);
  minHandler = handlerQueue.peekFirst();
  maxHandler = handlerQueue.peekLast();
 }
}

代码示例来源:origin: caskdata/cdap

HandlerSize<T> handlerSize = handlerQueue.removeFirst();
 assigner.set(handlerSize.getHandler(), partition.getName(), replica);
handlerQueue.removeFirst();

代码示例来源:origin: co.cask.cdap/cdap-common

HandlerSize<T> handlerSize = handlerQueue.removeFirst();
 assigner.set(handlerSize.getHandler(), partition.getName(), replica);
handlerQueue.removeFirst();

代码示例来源:origin: grafos-ml/okapi

private void sendUpdates(Vertex<LongWritable, IntWritable, MBMEdgeValue> vertex) {
  final MBMMessage proposeMsg = new MBMMessage(vertex.getId(), State.PROPOSED);
  // get top-capacity available edges by weight
  final int capacity = vertex.getValue().get();
  MinMaxPriorityQueue<Entry<LongWritable, MBMEdgeValue>> maxHeap = MinMaxPriorityQueue.orderedBy(new Comparator<Entry<LongWritable, MBMEdgeValue>>() {
    @Override
    public int compare(Entry<LongWritable, MBMEdgeValue> o1, Entry<LongWritable, MBMEdgeValue> o2) {
      return -1 * Double.compare(o1.getValue().getWeight(), o2.getValue().getWeight()); // reverse comparator, largest weight first
    }
  }).maximumSize(capacity).create();
  // prepare list of available edges
  for (Edge<LongWritable, MBMEdgeValue> e : vertex.getEdges()) {
    if (e.getValue().getState() == State.DEFAULT || e.getValue().getState() == State.PROPOSED) {
      maxHeap.add(Maps.immutableEntry(e.getTargetVertexId(), e.getValue()));
    }
  }
  if (maxHeap.isEmpty()) {
    // all remaining edges are INCLUDED, nothing else to do
    checkSolution(vertex.getEdges());
    vertex.voteToHalt();
  } else {
    // propose up to capacity
    while (!maxHeap.isEmpty()) {
      Entry<LongWritable, MBMEdgeValue> entry = maxHeap.removeFirst();
      vertex.getEdgeValue(entry.getKey()).setState(State.PROPOSED);
      sendMessage(entry.getKey(), proposeMsg);
    }
  }
}

相关文章