Package dovetaildb.util

Examples of dovetaildb.util.PriorityQueue


 
 
  public static SegmentPush balanceSegmentPush(SegmentPush segment, int threshold) {
    long ct = segment.count;
    if (ct <= threshold) return segment;
    PriorityQueue queue = new PriorityQueue(500) {
      @Override
      public int compare(Object a, Object b) {
        AdjacencyRec r1 = (AdjacencyRec)a;
        AdjacencyRec r2 = (AdjacencyRec)b;
        return (int)((r1.ct1+r2.ct2) - (r2.ct1+r2.ct2));
      }
    };
    Iterator<PostingNode> itr = segment.iterator();
    PostingNode firstNode = itr.next();
    PostingNode secondNode = itr.next();
    AdjacencyRec firstAdj = new AdjacencyRec(firstNode, secondNode);
    queue.insertAndGrow(firstAdj);
    AdjacencyRec prevAdj = firstAdj;
    while(itr.hasNext()) {
      PostingNode curNode = itr.next();
      AdjacencyRec adj = new AdjacencyRec(curNode, prevAdj);
      queue.insertAndGrow(adj);
      prevAdj = adj;
    }
    while(queue.size >= threshold) {
      AdjacencyRec rec = (AdjacencyRec)queue.pop();
      if (rec.dirty) {
        rec.dirty = false;
        queue.insert(rec);
      } else {
        rec.node1.addAll(rec.node2);
        if (rec.left != null) {
          rec.left.right = rec.right;
          rec.left.ct2 += rec.ct2;
View Full Code Here

TOP

Related Classes of dovetaildb.util.PriorityQueue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.