當前位置: 首頁>>代碼示例>>Java>>正文


Java MinMaxPriorityQueue.add方法代碼示例

本文整理匯總了Java中com.google.common.collect.MinMaxPriorityQueue.add方法的典型用法代碼示例。如果您正苦於以下問題:Java MinMaxPriorityQueue.add方法的具體用法?Java MinMaxPriorityQueue.add怎麽用?Java MinMaxPriorityQueue.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.collect.MinMaxPriorityQueue的用法示例。


在下文中一共展示了MinMaxPriorityQueue.add方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: rebuildCache

import com.google.common.collect.MinMaxPriorityQueue; //導入方法依賴的package包/類
public CachedPostingListCounter rebuildCache() {
    MinMaxPriorityQueue<Entry> mostExpensive = MinMaxPriorityQueue
            .maximumSize(32).expectedSize(32).create();
    synchronized (this) {
        for (ObjectLongPair<int[]> p : frequency.keyValuesView()) {
            mostExpensive.add(new Entry(p.getOne(), p.getTwo()));
        }
    }
    ObjectIntHashMap<int[]> postingListMapping = new ObjectIntHashMap<>();
    int[] bitVector = new int[nDocuments];
    int length = mostExpensive.size();
    for (int i = 0; i < length; i++) {
        Entry e = mostExpensive.removeFirst();
        int[] docIds = e.docIds;
        postingListMapping.put(docIds, i);
        for (int docId : docIds) {
            bitVector[docId] |= (1 << i);
        }
    }
    return new CachedPostingListCounter(postingListMapping, bitVector);
}
 
開發者ID:vespa-engine,項目名稱:vespa,代碼行數:22,代碼來源:CachedPostingListCounter.java

示例2: getSelectedLinks

import com.google.common.collect.MinMaxPriorityQueue; //導入方法依賴的package包/類
@Override
public List<LinkRelevance> getSelectedLinks() {
    List<LinkRelevance> links = new ArrayList<>();
    while (links.size() < numberOfLinks && !topkLinksPerDomain.isEmpty()) {
        // adds the URL with max score of each domain
        MinMaxPriorityQueue<LinkRelevance> topk = newPriorityQueue(numberOfLinks);
        Iterator<Entry<String, MinMaxPriorityQueue<LinkRelevance>>> it = topkLinksPerDomain.entrySet().iterator();
        while (it.hasNext()) {
            MinMaxPriorityQueue<LinkRelevance> domain = it.next().getValue();
            topk.add(domain.poll());
            if (domain.isEmpty()) {
                it.remove();
            }
        }
        for(LinkRelevance link : topk) {
            links.add(link);
        }
    }
    this.topkLinksPerDomain = null; // clean-up reference
    return links;
}
 
開發者ID:ViDA-NYU,項目名稱:ache,代碼行數:22,代碼來源:MaximizeWebsitesLinkSelector.java

示例3: tenantPartitionsLatestTopologies

import com.google.common.collect.MinMaxPriorityQueue; //導入方法依賴的package包/類
private NavigableMap<MiruPartitionId, MinMaxPriorityQueue<HostAndTimestamp>> tenantPartitionsLatestTopologies(MiruTenantId tenantId,
    Collection<MiruPartitionId> partitionIds) throws Exception {

    final NavigableMap<MiruPartitionId, MinMaxPriorityQueue<HostAndTimestamp>> partitionIdToLatest = new TreeMap<>();

    for (HostHeartbeat hostHeartbeat : getAllHosts()) {
        EmbeddedClient registryClient = registryClient(hostHeartbeat.host);
        for (MiruPartitionId partitionId : partitionIds) {
            byte[] got = registryClient.getValue(Consistency.quorum, null, toTopologyKey(tenantId, partitionId));
            if (got != null) {
                MinMaxPriorityQueue<HostAndTimestamp> latest = partitionIdToLatest.get(partitionId);
                if (latest == null) {
                    // TODO defaultNumberOfReplicas should come from config?
                    latest = MinMaxPriorityQueue.maximumSize(defaultNumberOfReplicas)
                        .expectedSize(defaultNumberOfReplicas)
                        .<HostAndTimestamp>create();
                    partitionIdToLatest.put(partitionId, latest);
                }
                latest.add(new HostAndTimestamp(hostHeartbeat.host, FilerIO.bytesLong(got)));
            }
        }
    }

    return partitionIdToLatest;
}
 
開發者ID:jivesoftware,項目名稱:miru,代碼行數:26,代碼來源:AmzaClusterRegistry.java

示例4: comparatorTest

import com.google.common.collect.MinMaxPriorityQueue; //導入方法依賴的package包/類
@Test
public void comparatorTest() throws Exception {

  MinMaxPriorityQueue<DimensionValueMetricPair> testQueue = MinMaxPriorityQueue.maximumSize(2).create();

  DimensionValueMetricPair d1 = new DimensionValueMetricPair("d1", 1);
  DimensionValueMetricPair d2 = new DimensionValueMetricPair("d2", 2);
  DimensionValueMetricPair d3 = new DimensionValueMetricPair(30, 3);
  DimensionValueMetricPair d4 = new DimensionValueMetricPair("d4", 4);

  testQueue.add(d1);
  testQueue.add(d2);
  testQueue.add(d3);
  testQueue.add(d4);

  for (DimensionValueMetricPair pair : testQueue) {
    Assert.assertEquals(pair.getMetricValue().intValue() > 2, true,
        "Incorrect comparator for DimensionValueMetricPair, queue must retain highest metric values");
  }

}
 
開發者ID:linkedin,項目名稱:pinot,代碼行數:22,代碼來源:DimensionValueMetricPairTest.java

示例5: worstFitDecreasingBinPacking

import com.google.common.collect.MinMaxPriorityQueue; //導入方法依賴的package包/類
/**
 * Pack a list of {@link WorkUnit}s into a smaller number of {@link MultiWorkUnit}s,
 * using the worst-fit-decreasing algorithm.
 *
 * Each {@link WorkUnit} is assigned to the {@link MultiWorkUnit} with the smallest load.
 */
protected List<WorkUnit> worstFitDecreasingBinPacking(List<WorkUnit> groups, int numOfMultiWorkUnits) {

  // Sort workunit groups by data size desc
  Collections.sort(groups, LOAD_DESC_COMPARATOR);

  MinMaxPriorityQueue<MultiWorkUnit> pQueue =
      MinMaxPriorityQueue.orderedBy(LOAD_ASC_COMPARATOR).expectedSize(numOfMultiWorkUnits).create();
  for (int i = 0; i < numOfMultiWorkUnits; i++) {
    MultiWorkUnit multiWorkUnit = new MultiWorkUnit();
    setWorkUnitEstSize(multiWorkUnit, 0);
    pQueue.add(multiWorkUnit);
  }

  for (WorkUnit group : groups) {
    MultiWorkUnit lightestMultiWorkUnit = pQueue.poll();
    addWorkUnitToMultiWorkUnit(group, lightestMultiWorkUnit);
    pQueue.add(lightestMultiWorkUnit);
  }

  logMultiWorkUnitInfo(pQueue);

  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,
      maxLoad, (maxLoad - minLoad) / maxLoad * 100.0));

  this.state.setProp(MIN_MULTIWORKUNIT_LOAD, minLoad);
  this.state.setProp(MAX_MULTIWORKUNIT_LOAD, maxLoad);

  List<WorkUnit> multiWorkUnits = Lists.newArrayList();
  multiWorkUnits.addAll(pQueue);
  return multiWorkUnits;
}
 
開發者ID:Hanmourang,項目名稱:Gobblin,代碼行數:40,代碼來源:KafkaWorkUnitPacker.java

示例6: evaluateLink

import com.google.common.collect.MinMaxPriorityQueue; //導入方法依賴的package包/類
@Override
public void evaluateLink(LinkRelevance link) {
    if (link.getRelevance() > 0) {
        String domainName = link.getTopLevelDomainName();
        MinMaxPriorityQueue<LinkRelevance> domainQueue = topkLinksPerDomain.get(domainName);
        if (domainQueue == null) {
            domainQueue = newPriorityQueue(MAX_LINKS_PER_DOMAIN);
            topkLinksPerDomain.put(domainName, domainQueue);
        }
        domainQueue.add(link);
    }
}
 
開發者ID:ViDA-NYU,項目名稱:ache,代碼行數:13,代碼來源:MaximizeWebsitesLinkSelector.java

示例7: worstFitDecreasingBinPacking

import com.google.common.collect.MinMaxPriorityQueue; //導入方法依賴的package包/類
/**
 * Pack a list of {@link WorkUnit}s into a smaller number of {@link MultiWorkUnit}s,
 * using the worst-fit-decreasing algorithm.
 *
 * Each {@link WorkUnit} is assigned to the {@link MultiWorkUnit} with the smallest load.
 */
protected List<WorkUnit> worstFitDecreasingBinPacking(List<WorkUnit> groups, int numOfMultiWorkUnits) {

  // Sort workunit groups by data size desc
  Collections.sort(groups, LOAD_DESC_COMPARATOR);

  MinMaxPriorityQueue<MultiWorkUnit> pQueue =
      MinMaxPriorityQueue.orderedBy(LOAD_ASC_COMPARATOR).expectedSize(numOfMultiWorkUnits).create();
  for (int i = 0; i < numOfMultiWorkUnits; i++) {
    MultiWorkUnit multiWorkUnit = MultiWorkUnit.createEmpty();
    setWorkUnitEstSize(multiWorkUnit, 0);
    pQueue.add(multiWorkUnit);
  }

  for (WorkUnit group : groups) {
    MultiWorkUnit lightestMultiWorkUnit = pQueue.poll();
    addWorkUnitToMultiWorkUnit(group, lightestMultiWorkUnit);
    pQueue.add(lightestMultiWorkUnit);
  }

  logMultiWorkUnitInfo(pQueue);

  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,
      maxLoad, (maxLoad - minLoad) / maxLoad * 100.0));

  this.state.setProp(MIN_MULTIWORKUNIT_LOAD, minLoad);
  this.state.setProp(MAX_MULTIWORKUNIT_LOAD, maxLoad);

  List<WorkUnit> multiWorkUnits = Lists.newArrayList();
  multiWorkUnits.addAll(pQueue);
  return multiWorkUnits;
}
 
開發者ID:apache,項目名稱:incubator-gobblin,代碼行數:40,代碼來源:KafkaWorkUnitPacker.java

示例8: tenantLatestTopology

import com.google.common.collect.MinMaxPriorityQueue; //導入方法依賴的package包/類
private MinMaxPriorityQueue<HostAndTimestamp> tenantLatestTopology(MiruTenantId tenantId, MiruPartitionId partitionId) throws Exception {
    // TODO defaultNumberOfReplicas should come from config?
    MinMaxPriorityQueue<HostAndTimestamp> latest = MinMaxPriorityQueue.maximumSize(defaultNumberOfReplicas)
        .expectedSize(defaultNumberOfReplicas)
        .create();
    for (HostHeartbeat hostHeartbeat : getAllHosts()) {
        EmbeddedClient registryClient = registryClient(hostHeartbeat.host);
        byte[] got = registryClient.getValue(Consistency.quorum, null, toTopologyKey(tenantId, partitionId));
        if (got != null) {
            latest.add(new HostAndTimestamp(hostHeartbeat.host, FilerIO.bytesLong(got)));
        }
    }
    return latest;
}
 
開發者ID:jivesoftware,項目名稱:miru,代碼行數:15,代碼來源:AmzaClusterRegistry.java

示例9: MinMaxQueueTest

import com.google.common.collect.MinMaxPriorityQueue; //導入方法依賴的package包/類
@Test
    public void MinMaxQueueTest() throws Exception {
        int maxListLength = 4;
        MinMaxPriorityQueue<WikiSimComparableResult<Double>> queue = MinMaxPriorityQueue
                .orderedBy(new Comparator<WikiSimComparableResult<Double>>() {
                    @Override
                    public int compare(WikiSimComparableResult<Double> o1, WikiSimComparableResult<Double> o2) {
                        return -1 * o1.compareTo(o2);
                    }
                })
                .maximumSize(maxListLength).create();

        WikiSimComparableResult<Double> testItemLow = new WikiSimComparableResult<>("B", 2.0, 0);
        WikiSimComparableResult<Double> testItemHigh = new WikiSimComparableResult<>("A", 5.0, 0);

        queue.add(testItemLow);
        queue.add(testItemLow);
        queue.add(testItemLow);
        queue.add(testItemLow);
        queue.add(testItemHigh);
        queue.add(new WikiSimComparableResult<>("A", 4.0, 0));
        queue.add(new WikiSimComparableResult<>("A", 3.0,0));
        queue.add(new WikiSimComparableResult<>("A", 2.0,0));
        queue.add(testItemLow);

//        System.out.println("Simple Queue" + queue);

        if (queue.contains(testItemLow)) {
            throw new Exception("testItemLow NOT should exist in queue: " + testItemLow);
        }

        if (!queue.contains(testItemHigh)) {
            throw new Exception("testItemHigh should exist in queue: " + testItemHigh);
        }

        if (testItemHigh.compareTo(testItemLow) != 1) {
            throw new Exception(testItemHigh + " compareTo " + testItemLow + " = " + testItemHigh.compareTo(testItemLow) + " // should be = 1");
        }

    }
 
開發者ID:wikimedia,項目名稱:citolytics,代碼行數:41,代碼來源:EvaluationTest.java

示例10: getTopKUnSorted

import com.google.common.collect.MinMaxPriorityQueue; //導入方法依賴的package包/類
@Override
public long[] getTopKUnSorted() {
	final MinMaxPriorityQueue<Long> queue = MinMaxPriorityQueue
			.maximumSize(k).create();
	long d = 0;
	int i = 0;
	while ((d = iterator.getNextLong()) != -1) {
		queue.add(setDistance(d, i));
		i++;
	}
	return Longs.toArray(queue);
}
 
開發者ID:jsubercaze,項目名稱:simhashdb,代碼行數:13,代碼來源:GuavaMinMaxTopK.java

示例11: joinTopKs

import com.google.common.collect.MinMaxPriorityQueue; //導入方法依賴的package包/類
@Override
public long[] joinTopKs(final long[]... topks) {
	final MinMaxPriorityQueue<Long> queue = MinMaxPriorityQueue
			.maximumSize(k).create();
	for (final long[] ls : topks) {
		for (final long dist : ls) {
			queue.add(dist);
		}
	}
	return Longs.toArray(queue);
}
 
開發者ID:jsubercaze,項目名稱:simhashdb,代碼行數:12,代碼來源:GuavaMinMaxTopK.java

示例12: mainkNearestNeighbors2

import com.google.common.collect.MinMaxPriorityQueue; //導入方法依賴的package包/類
private Long[] mainkNearestNeighbors2(final long[] query, final int k) {
	final MinMaxPriorityQueue<Long> minmaxqueue = MinMaxPriorityQueue
			.maximumSize(k).create();
	final int i = 0;
	for (final long[] hash : hashes) {
		long d = distance(query, hash);
		// System.out.println("Distance with " + i + " " + d);
		d = d << 32;
		d += i;
		minmaxqueue.add(d);
	}
	final Long[] result = minmaxqueue.toArray(new Long[minmaxqueue.size()]);
	return result;

}
 
開發者ID:jsubercaze,項目名稱:simhashdb,代碼行數:16,代碼來源:InMemorySimHashDB.java

示例13: cleanup

import com.google.common.collect.MinMaxPriorityQueue; //導入方法依賴的package包/類
@Override
protected void cleanup(Context context) throws IOException, InterruptedException {

  for (String dimension : dimensionNames) {

    LOGGER.info("{} records passed metric threshold for dimension {}", thresholdPassCount.get(dimension), dimension);

    // Get top k
    TopKDimensionToMetricsSpec topkSpec = topKDimensionToMetricsSpecMap.get(dimension);
    if (topkSpec != null && topkSpec.getDimensionName() != null && topkSpec.getTopk() != null) {

      // Get top k for each metric specified
      Map<String, Integer> topkMetricsMap = topkSpec.getTopk();
      for (Entry<String, Integer> topKEntry : topkMetricsMap.entrySet()) {

        String metric = topKEntry.getKey();
        int k = topKEntry.getValue();
        MinMaxPriorityQueue<DimensionValueMetricPair> topKQueue = MinMaxPriorityQueue.maximumSize(k).create();

        Map<Object, Number[]> dimensionToMetricsMap = dimensionNameToValuesMap.get(dimension);
        for (Entry<Object, Number[]> entry : dimensionToMetricsMap.entrySet()) {
          topKQueue.add(new DimensionValueMetricPair(entry.getKey(), entry.getValue()[metricToIndexMapping.get(metric)]));
        }
        LOGGER.info("Picking Top {} values for {} based on Metric {} : {}", k, dimension, metric, topKQueue);
        for (DimensionValueMetricPair pair : topKQueue) {
          topkDimensionValues.addValue(dimension, String.valueOf(pair.getDimensionValue()));
        }
      }
    }
  }

  if (topkDimensionValues.getTopKDimensions().size() > 0) {
    String topkValuesPath = configuration.get(TOPK_PHASE_OUTPUT_PATH.toString());
    LOGGER.info("Writing top k values to {}",topkValuesPath);
    FSDataOutputStream topKDimensionValuesOutputStream = fileSystem.create(
        new Path(topkValuesPath + File.separator + ThirdEyeConstants.TOPK_VALUES_FILE));
    OBJECT_MAPPER.writeValue((DataOutput) topKDimensionValuesOutputStream, topkDimensionValues);
    topKDimensionValuesOutputStream.close();
  }
}
 
開發者ID:linkedin,項目名稱:pinot,代碼行數:41,代碼來源:TopKPhaseJob.java


注:本文中的com.google.common.collect.MinMaxPriorityQueue.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。