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


Java MinMaxPriorityQueue類代碼示例

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


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

示例1: CachedEntryQueue

import com.google.common.collect.MinMaxPriorityQueue; //導入依賴的package包/類
/**
 * @param maxSize the target size of elements in the queue
 * @param blockSize expected average size of blocks
 */
public CachedEntryQueue(long maxSize, long blockSize) {
  int initialSize = (int) (maxSize / blockSize);
  if (initialSize == 0) {
    initialSize++;
  }
  queue = MinMaxPriorityQueue.orderedBy(new Comparator<Map.Entry<BlockCacheKey, BucketEntry>>() {

    public int compare(Entry<BlockCacheKey, BucketEntry> entry1,
        Entry<BlockCacheKey, BucketEntry> entry2) {
      return BucketEntry.COMPARATOR.compare(entry1.getValue(), entry2.getValue());
    }

  }).expectedSize(initialSize).create();
  cacheSize = 0;
  this.maxSize = maxSize;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:21,代碼來源:CachedEntryQueue.java

示例2: 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

示例3: queryKNN

import com.google.common.collect.MinMaxPriorityQueue; //導入依賴的package包/類
public Queue<QueryMatch> queryKNN(double lat, double lon, int n)
  throws IOException {
  DistanceComparator comp = new DistanceComparator(lon, lat);
  Queue<QueryMatch> ret
    = MinMaxPriorityQueue.orderedBy(comp)
    .maximumSize(n)
    .create();

  GeoHash target = GeoHash.withCharacterPrecision(lat, lon, precision);
  ret.addAll(takeN(comp, target.toBase32(), n));
  for (GeoHash h : target.getAdjacent()) {
    ret.addAll(takeN(comp, h.toBase32(), n));
  }

  return ret;
}
 
開發者ID:East196,項目名稱:maker,代碼行數:17,代碼來源:KNNQuery.java

示例4: CachedEntryQueue

import com.google.common.collect.MinMaxPriorityQueue; //導入依賴的package包/類
/**
 * @param maxSize the target size of elements in the queue
 * @param blockSize expected average size of blocks
 */
public CachedEntryQueue(long maxSize, long blockSize) {
  int initialSize = (int) (maxSize / blockSize);
  if (initialSize == 0)
    initialSize++;
  queue = MinMaxPriorityQueue
      .orderedBy(new Comparator<Map.Entry<BlockCacheKey, BucketEntry>>() {
        public int compare(Entry<BlockCacheKey, BucketEntry> entry1,
            Entry<BlockCacheKey, BucketEntry> entry2) {
          return entry1.getValue().compareTo(entry2.getValue());
        }

      }).expectedSize(initialSize).create();
  cacheSize = 0;
  this.maxSize = maxSize;
}
 
開發者ID:grokcoder,項目名稱:pbase,代碼行數:20,代碼來源:CachedEntryQueue.java

示例5: 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

示例6: getPartitionsForTenant

import com.google.common.collect.MinMaxPriorityQueue; //導入依賴的package包/類
@Override
public List<MiruPartition> getPartitionsForTenant(MiruTenantId tenantId) throws Exception {
    NavigableMap<MiruPartitionId, MinMaxPriorityQueue<HostAndTimestamp>> partitionIdToLatest = tenantLatestTopologies(tenantId);

    List<MiruPartition> partitions = new ArrayList<>();
    for (MiruPartitionId partitionId : partitionIdToLatest.keySet()) {
        MinMaxPriorityQueue<HostAndTimestamp> got = partitionIdToLatest.get(partitionId);
        for (HostAndTimestamp hat : got) {
            EmbeddedClient topologyInfoClient = topologyInfoClient(hat.host);
            byte[] rawInfo = topologyInfoClient.getValue(Consistency.none, null, toTopologyKey(tenantId, partitionId));
            MiruPartitionCoordInfo info;
            if (rawInfo == null) {
                info = new MiruPartitionCoordInfo(MiruPartitionState.offline, MiruBackingStorage.memory);
            } else {
                MiruTopologyColumnValue columnValue = topologyColumnValueMarshaller.fromBytes(rawInfo);
                info = new MiruPartitionCoordInfo(columnValue.state, columnValue.storage);
            }
            partitions.add(new MiruPartition(new MiruPartitionCoord(tenantId, partitionId, hat.host), info));
        }
    }
    return partitions;
}
 
開發者ID:jivesoftware,項目名稱:miru,代碼行數:23,代碼來源:AmzaClusterRegistry.java

示例7: 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

示例8: getPartitionsForTenantHost

import com.google.common.collect.MinMaxPriorityQueue; //導入依賴的package包/類
@Override
public List<MiruPartition> getPartitionsForTenantHost(MiruTenantId tenantId, MiruHost host) throws Exception {
    NavigableMap<MiruPartitionId, MinMaxPriorityQueue<HostAndTimestamp>> partitionIdToLatest = tenantLatestTopologies(tenantId);
    List<MiruPartition> partitions = new ArrayList<>();
    for (MiruPartitionId partitionId : partitionIdToLatest.keySet()) {
        MinMaxPriorityQueue<HostAndTimestamp> got = partitionIdToLatest.get(partitionId);
        for (HostAndTimestamp hat : got) {
            if (hat.host.equals(host)) {
                EmbeddedClient topologyInfoClient = topologyInfoClient(hat.host);
                byte[] rawInfo = topologyInfoClient.getValue(Consistency.none, null, toTopologyKey(tenantId, partitionId));
                MiruPartitionCoordInfo info;
                if (rawInfo == null) {
                    info = new MiruPartitionCoordInfo(MiruPartitionState.offline, MiruBackingStorage.memory);
                } else {
                    MiruTopologyColumnValue columnValue = topologyColumnValueMarshaller.fromBytes(rawInfo);
                    info = new MiruPartitionCoordInfo(columnValue.state, columnValue.storage);
                }
                partitions.add(new MiruPartition(new MiruPartitionCoord(tenantId, partitionId, hat.host), info));
            }
        }
    }
    return partitions;
}
 
開發者ID:jivesoftware,項目名稱:miru,代碼行數:24,代碼來源:AmzaClusterRegistry.java

示例9: getReplicaSet

import com.google.common.collect.MinMaxPriorityQueue; //導入依賴的package包/類
@Override
public MiruReplicaSet getReplicaSet(MiruTenantId tenantId, MiruPartitionId partitionId) throws Exception {
    MinMaxPriorityQueue<HostAndTimestamp> latest = tenantLatestTopology(tenantId, partitionId);
    List<MiruPartition> partitions = Lists.newArrayList();
    Set<MiruHost> replicaHosts = Sets.newHashSet();

    for (HostAndTimestamp hat : latest) {
        EmbeddedClient topologyInfoClient = topologyInfoClient(hat.host);
        byte[] rawInfo = topologyInfoClient.getValue(Consistency.none, null, toTopologyKey(tenantId, partitionId));
        MiruPartitionCoordInfo info;
        if (rawInfo == null) {
            info = new MiruPartitionCoordInfo(MiruPartitionState.offline, MiruBackingStorage.memory);
        } else {
            MiruTopologyColumnValue columnValue = topologyColumnValueMarshaller.fromBytes(rawInfo);
            info = new MiruPartitionCoordInfo(columnValue.state, columnValue.storage);
        }
        partitions.add(new MiruPartition(new MiruPartitionCoord(tenantId, partitionId, hat.host), info));
        replicaHosts.add(hat.host);
    }

    int missing = defaultNumberOfReplicas - replicaHosts.size(); // TODO expose to config?
    return new MiruReplicaSet(extractPartitionsByState(partitions), replicaHosts, missing, defaultNumberOfReplicas);
}
 
開發者ID:jivesoftware,項目名稱:miru,代碼行數:24,代碼來源:AmzaClusterRegistry.java

示例10: composeAnswer

import com.google.common.collect.MinMaxPriorityQueue; //導入依賴的package包/類
private <BM extends IBM, IBM> RecoAnswer composeAnswer(MiruRequestContext<BM, IBM, ?> requestContext,
    MiruRequest<RecoQuery> request,
    MiruFieldDefinition fieldDefinition,
    MinMaxPriorityQueue<MiruTermCount> heap,
    StackBuffer stackBuffer) throws Exception {

    MiruSchema schema = requestContext.getSchema();
    MiruTermComposer termComposer = requestContext.getTermComposer();
    List<Recommendation> results = new ArrayList<>();
    for (MiruTermCount result : heap) {
        MiruValue term = new MiruValue(termComposer.decompose(schema, fieldDefinition, stackBuffer, result.termId));
        results.add(new Recommendation(term, result.count));
    }
    log.debug("score: results.size={}", results.size());
    boolean resultsExhausted = request.query.timeRange.smallestTimestamp > requestContext.getTimeIndex().getLargestTimestamp();
    return new RecoAnswer(results, 1, resultsExhausted);
}
 
開發者ID:jivesoftware,項目名稱:miru,代碼行數:18,代碼來源:CollaborativeFiltering.java

示例11: completeCommittingSegments

import com.google.common.collect.MinMaxPriorityQueue; //導入依賴的package包/類
public void completeCommittingSegments(String realtimeTableName, List<String> segmentIds) {
  Comparator<LLCSegmentName> comparator = new Comparator<LLCSegmentName>() {
    @Override
    public int compare(LLCSegmentName o1, LLCSegmentName o2) {
      return o2.compareTo(o1);
    }
  };

  Map<Integer, MinMaxPriorityQueue<LLCSegmentName>> partitionToLatestSegments = new HashMap<>();

  for (String segmentId : segmentIds) {
    LLCSegmentName segmentName = new LLCSegmentName(segmentId);
    final int partitionId = segmentName.getPartitionId();
    MinMaxPriorityQueue latestSegments = partitionToLatestSegments.get(partitionId);
    if (latestSegments == null) {
      latestSegments = MinMaxPriorityQueue.orderedBy(comparator).maximumSize(2).create();
      partitionToLatestSegments.put(partitionId, latestSegments);
    }
    latestSegments.offer(segmentName);
  }

  completeCommittingSegmentsInternal(realtimeTableName, partitionToLatestSegments);
}
 
開發者ID:linkedin,項目名稱:pinot,代碼行數:24,代碼來源:PinotLLCRealtimeSegmentManager.java

示例12: 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

示例13: addRegionPlan

import com.google.common.collect.MinMaxPriorityQueue; //導入依賴的package包/類
/**
 * Add a region from the head or tail to the List of regions to return.
 */
private void addRegionPlan(final MinMaxPriorityQueue<RegionPlan> regionsToMove,
    final boolean fetchFromTail, final ServerName sn, List<RegionPlan> regionsToReturn) {
  RegionPlan rp = null;
  if (!fetchFromTail) rp = regionsToMove.remove();
  else rp = regionsToMove.removeLast();
  rp.setDestination(sn);
  regionsToReturn.add(rp);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:12,代碼來源:SimpleLoadBalancer.java

示例14: LruCachedBlockQueue

import com.google.common.collect.MinMaxPriorityQueue; //導入依賴的package包/類
/**
 * @param maxSize the target size of elements in the queue
 * @param blockSize expected average size of blocks
 */
public LruCachedBlockQueue(long maxSize, long blockSize) {
  int initialSize = (int)(maxSize / blockSize);
  if(initialSize == 0) initialSize++;
  queue = MinMaxPriorityQueue.expectedSize(initialSize).create();
  heapSize = 0;
  this.maxSize = maxSize;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:12,代碼來源:LruCachedBlockQueue.java

示例15: ReservoirSampler

import com.google.common.collect.MinMaxPriorityQueue; //導入依賴的package包/類
public ReservoirSampler(final int k, final Random random, final ToDoubleFunction<Integer> computeWeight) {
    this.minQueue = MinMaxPriorityQueue
            .<Pair<Double, T>>orderedBy((x, y) -> Double.compare(x.first(), y.first()))
            .maximumSize(k).create();
    this.computeWeight = computeWeight;
    this.random = random;
    this.count = new AtomicInteger(0);
}
 
開發者ID:uwnlp,項目名稱:neuralccg,代碼行數:9,代碼來源:ReservoirSampler.java


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