Example usage for java.util PriorityQueue size

List of usage examples for java.util PriorityQueue size

Introduction

In this page you can find the example usage for java.util PriorityQueue size.

Prototype

int size

To view the source code for java.util PriorityQueue size.

Click Source Link

Document

The number of elements in the priority queue.

Usage

From source file:Main.java

public static void main(String args[]) {

    PriorityQueue<Integer> prq = new PriorityQueue<Integer>();

    for (int i = 3; i < 10; i++) {
        prq.add(i);/*w  w w  .ja va2s .co m*/
    }

    System.out.println("Size of the queue is: " + prq.size());

    System.out.println(prq);
}

From source file:hivemall.knn.lsh.MinHashUDTF.java

private static int getSignature(PriorityQueue<Integer> candidates, int keyGroups) {
    final int numCandidates = candidates.size();
    if (numCandidates == 0) {
        return 0;
    }//from w  w w. jav  a 2  s  . co m

    final int size = Math.min(numCandidates, keyGroups);
    int result = 1;
    for (int i = 0; i < size; i++) {
        int nextmin = candidates.poll();
        result = (31 * result) + nextmin;
    }
    return result & 0x7FFFFFFF;
}

From source file:net.spfbl.core.Huffman.java

private static Huffman buildTree(int[] frequency) {
    PriorityQueue<Huffman> queue = new PriorityQueue<Huffman>();
    for (char i = 0; i < 256; i++) {
        if (frequency[i] > 0) {
            queue.add(new Huffman(i, frequency[i], null, null));
        }//from  w  w  w. j a  v a  2  s  .  co  m
    }
    if (queue.size() == 1) {
        if (frequency['\0'] == 0) {
            queue.add(new Huffman('\0', 0, null, null));
        } else {
            queue.add(new Huffman('\1', 0, null, null));
        }
    }
    while (queue.size() > 1) {
        Huffman left = queue.poll();
        Huffman right = queue.poll();
        Huffman parent = new Huffman('\0', left.frequency + right.frequency, left, right);
        queue.add(parent);
    }
    return queue.poll();
}

From source file:org.sample.whiteboardapp.MyWhiteboard.java

static JSONObject findKNN(double[] Qpoint, Node root, int k) {
    JSONObject coordinates = new JSONObject();
    JSONArray lat_json = new JSONArray();
    JSONArray long_json = new JSONArray();
    PriorityQueue<Double> pq = new PriorityQueue<Double>(10, Collections.reverseOrder());
    HashMap<Double, Node> hm = new HashMap();
    searchKDSubtree(pq, hm, root, Qpoint, k, 0);
    System.out.println(pq.size());
    while (pq.size() != 0) {
        Node ans = hm.get(pq.poll());
        System.out.println(ans.point[0] + " " + ans.point[1]);
        System.out.println(pq.size());
        lat_json.add(ans.point[0]);//from  w  ww .ja va 2 s.  co  m
        long_json.add(ans.point[1]);

    }
    coordinates.put("latitude", lat_json);
    coordinates.put("longitude", long_json);
    return coordinates;

}

From source file:org.sample.whiteboardapp.MyWhiteboard.java

static void searchKDSubtree(PriorityQueue<Double> pq, HashMap<Double, Node> hm, Node root, double[] Qpoint,
        int k, int depth) {
    Node child = null;/*from   w  ww  .java 2 s .c o  m*/
    int dim = depth;
    double dist = Distance(Qpoint, root.point);

    if (pq.size() < k) {
        pq.add(dist);
        hm.put(dist, root);
    } else if (dist < pq.peek()) {
        pq.poll();
        pq.add(dist);
        hm.put(dist, root);
    }
    if (Qpoint[dim] < root.point[dim]) {
        if (root.left != null) {
            searchKDSubtree(pq, hm, root.left, Qpoint, k, (depth + 1) % 2);
            child = root.right;
        }
    } else {
        if (root.right != null) {
            searchKDSubtree(pq, hm, root.right, Qpoint, k, (depth + 1) % 2);
            child = root.left;
        }
    }
    if ((pq.size() < k || (Qpoint[dim] - root.point[dim]) < pq.peek()) && child != null) {
        searchKDSubtree(pq, hm, child, Qpoint, k, (depth + 1) % 2);
    }
}

From source file:Main.java

public static List<String> getSortedStringList(Collection<String> toSort) {
    List<String> sorted = new LinkedList<String>();
    final PriorityQueue<String> ordered = new PriorityQueue<String>(
            toSort.size() + 1/*In case the toSort is empty*/, new Comparator<String>() {
                @Override//  w ww  .  j a v a  2s. c o m
                public int compare(String lhs, String rhs) {
                    lhs = lhs.replaceAll("[^a-zA-Z0-9]", "");
                    rhs = rhs.replaceAll("[^a-zA-Z0-9]", "");
                    int result = rhs.compareTo(lhs);
                    return result;
                }
            });
    ordered.addAll(toSort);
    int originalSize = ordered.size();
    for (int i = 0; i < originalSize; i++) {
        sorted.add(ordered.poll());
    }
    return sorted;
}

From source file:org.apache.pig.builtin.TOP.java

protected static void updateTop(PriorityQueue<Tuple> store, int limit, DataBag inputBag) {
    Iterator<Tuple> itr = inputBag.iterator();
    while (itr.hasNext()) {
        Tuple t = itr.next();/*  w  w  w . j  ava 2 s.  c  om*/
        store.add(t);
        if (store.size() > limit)
            store.poll();
    }
}

From source file:org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreHelper.java

private static Iterable<BlobReferences> scan(DocumentNodeStore store, Comparator<BlobReferences> comparator,
        int num) {
    long totalGarbage = 0;
    Iterable<NodeDocument> docs = getDocuments(store.getDocumentStore());
    PriorityQueue<BlobReferences> queue = new PriorityQueue<BlobReferences>(num, comparator);
    List<Blob> blobs = Lists.newArrayList();
    long docCount = 0;
    for (NodeDocument doc : docs) {
        if (++docCount % 10000 == 0) {
            System.out.print(".");
        }//from w  ww.j a va  2s  . c o m
        blobs.clear();
        BlobReferences refs = collectReferences(doc, store);
        totalGarbage += refs.garbageSize;
        queue.add(refs);
        if (queue.size() > num) {
            queue.remove();
        }
    }

    System.out.println();
    List<BlobReferences> refs = Lists.newArrayList();
    refs.addAll(queue);
    Collections.sort(refs, Collections.reverseOrder(comparator));
    System.out.println("Total garbage size: " + FileUtils.byteCountToDisplaySize(totalGarbage));
    System.out.println("Total number of nodes with blob references: " + docCount);
    System.out.println("total referenced / old referenced / # blob references / path");
    return refs;
}

From source file:main.java.RMDupper.java

public static void queueOrOutput(DupStats dupStats, OccurenceCounterMerged occurenceCounterMerged,
        SAMFileWriter outputSam, Boolean allReadsAsMerged,
        PriorityQueue<ImmutableTriple<Integer, Integer, SAMRecord>> recordBuffer,
        PriorityQueue<ImmutableTriple<Integer, Integer, SAMRecord>> duplicateBuffer, Set<String> discardSet,
        SAMRecord curr) {/* w ww .j  a  v  a2  s.c o  m*/
    //Don't do anything with unmapped reads, just write them into the output!
    if (curr.getReadUnmappedFlag() || curr.getMappingQuality() == 0) {
        outputSam.addAlignment(curr);
    } else {
        if (recordBuffer.size() > 0 && recordBuffer.peek().middle < curr.getAlignmentStart()) {
            checkForDuplication(dupStats, occurenceCounterMerged, outputSam, allReadsAsMerged, recordBuffer,
                    duplicateBuffer, discardSet);
        }
        recordBuffer.add(new ImmutableTriple<Integer, Integer, SAMRecord>(curr.getAlignmentStart(),
                curr.getAlignmentEnd(), curr));
    }
}

From source file:com.aliyun.odps.mapred.local.MapOutputBuffer.java

public long getTotalRecordCount() {
    if (buffers == null) {
        return 0;
    }/* w  ww  . jav  a2 s  .  c o m*/
    long totalCount = 0;
    for (PriorityQueue<Object[]> item : buffers) {
        if (item == null) {
            continue;
        }
        totalCount += item.size();
    }
    return totalCount;
}