本文整理了Java中com.google.common.collect.MinMaxPriorityQueue.peekFirst()
方法的一些代码示例,展示了MinMaxPriorityQueue.peekFirst()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MinMaxPriorityQueue.peekFirst()
方法的具体详情如下:
包路径:com.google.common.collect.MinMaxPriorityQueue
类名称:MinMaxPriorityQueue
方法名:peekFirst
[英]Retrieves, but does not remove, the least element of this queue, or returns null if the queue is empty.
[中]检索但不删除此队列的最小元素,如果队列为空,则返回null。
代码示例来源:origin: apache/incubator-gobblin
double minLoad = getWorkUnitEstLoad(pQueue.peekFirst());
double maxLoad = getWorkUnitEstLoad(pQueue.peekLast());
LOG.info(String.format("Min load of multiWorkUnit = %f; Max load of multiWorkUnit = %f; Diff = %f%%", minLoad,
代码示例来源:origin: forcedotcom/phoenix
@Override
public ResultEntry peek() {
if (mergedQueue == null) {
mergedQueue = MinMaxPriorityQueue.<ResultEntry> orderedBy(
comparator).maximumSize(queues.size()).create();
for (MappedByteBufferPriorityQueue queue : queues) {
try {
IndexedResultEntry next = queue.getNextResult();
if (next != null) {
mergedQueue.add(next);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
if (!mergedQueue.isEmpty()) {
IndexedResultEntry re = mergedQueue.peekFirst();
if (re != null) {
return re;
}
}
return null;
}
代码示例来源: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: org.apache.gobblin/gobblin-kafka-common
double minLoad = getWorkUnitEstLoad(pQueue.peekFirst());
double maxLoad = getWorkUnitEstLoad(pQueue.peekLast());
LOG.info(String.format("Min load of multiWorkUnit = %f; Max load of multiWorkUnit = %f; Diff = %f%%", minLoad,
代码示例来源:origin: linkfluence/fastText4j
public void findKBest(int k,
float threshold,
MinMaxPriorityQueue<Pair<Float, Integer>> heap,
Vector hidden,
Vector output) {
computeOutputSoftmax(hidden, output);
for (int i = 0; i < osz; i++) {
if (output.data[i] < threshold) continue;
if (heap.size() == k && stdLog(output.data[i]) < heap.peekFirst().first()) {
continue;
}
heap.add(new Pair<>(stdLog(output.data[i]), i));
}
while (heap.size() > k) {
heap.pollLast();
}
}
内容来源于网络,如有侵权,请联系作者删除!