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:org.apache.accumulo.tserver.tablet.Tablet.java

private Set<FileRef> removeSmallest(Map<FileRef, DataFileValue> filesToCompact, int maxFilesToCompact) {
    // ensure this method works properly when multiple files have the same size

    // short-circuit; also handles zero files case
    if (filesToCompact.size() <= maxFilesToCompact) {
        Set<FileRef> smallestFiles = new HashSet<FileRef>(filesToCompact.keySet());
        filesToCompact.clear();//from   w  ww.ja va 2  s.  c  om
        return smallestFiles;
    }

    PriorityQueue<Pair<FileRef, Long>> fileHeap = new PriorityQueue<Pair<FileRef, Long>>(filesToCompact.size(),
            new Comparator<Pair<FileRef, Long>>() {
                @Override
                public int compare(Pair<FileRef, Long> o1, Pair<FileRef, Long> o2) {
                    if (o1.getSecond() == o2.getSecond())
                        return o1.getFirst().compareTo(o2.getFirst());
                    if (o1.getSecond() < o2.getSecond())
                        return -1;
                    return 1;
                }
            });

    for (Iterator<Entry<FileRef, DataFileValue>> iterator = filesToCompact.entrySet().iterator(); iterator
            .hasNext();) {
        Entry<FileRef, DataFileValue> entry = iterator.next();
        fileHeap.add(new Pair<FileRef, Long>(entry.getKey(), entry.getValue().getSize()));
    }

    Set<FileRef> smallestFiles = new HashSet<FileRef>();
    while (smallestFiles.size() < maxFilesToCompact && fileHeap.size() > 0) {
        Pair<FileRef, Long> pair = fileHeap.remove();
        filesToCompact.remove(pair.getFirst());
        smallestFiles.add(pair.getFirst());
    }

    return smallestFiles;
}

From source file:org.apache.accumulo.server.tabletserver.Tablet.java

private Set<FileRef> removeSmallest(Map<FileRef, Long> filesToCompact, int maxFilesToCompact) {
    // ensure this method works properly when multiple files have the same size

    PriorityQueue<Pair<FileRef, Long>> fileHeap = new PriorityQueue<Pair<FileRef, Long>>(filesToCompact.size(),
            new Comparator<Pair<FileRef, Long>>() {
                @Override//from  w w  w.j  a  va  2s.c om
                public int compare(Pair<FileRef, Long> o1, Pair<FileRef, Long> o2) {
                    if (o1.getSecond() == o2.getSecond())
                        return o1.getFirst().compareTo(o2.getFirst());
                    if (o1.getSecond() < o2.getSecond())
                        return -1;
                    return 1;
                }
            });

    for (Iterator<Entry<FileRef, Long>> iterator = filesToCompact.entrySet().iterator(); iterator.hasNext();) {
        Entry<FileRef, Long> entry = iterator.next();
        fileHeap.add(new Pair<FileRef, Long>(entry.getKey(), entry.getValue()));
    }

    Set<FileRef> smallestFiles = new HashSet<FileRef>();
    while (smallestFiles.size() < maxFilesToCompact && fileHeap.size() > 0) {
        Pair<FileRef, Long> pair = fileHeap.remove();
        filesToCompact.remove(pair.getFirst());
        smallestFiles.add(pair.getFirst());
    }

    return smallestFiles;
}

From source file:org.apache.accumulo.tserver.Tablet.java

private Set<FileRef> removeSmallest(Map<FileRef, DataFileValue> filesToCompact, int maxFilesToCompact) {
    // ensure this method works properly when multiple files have the same size

    PriorityQueue<Pair<FileRef, Long>> fileHeap = new PriorityQueue<Pair<FileRef, Long>>(filesToCompact.size(),
            new Comparator<Pair<FileRef, Long>>() {
                @Override//from ww  w  .j  a  va 2  s  . c  o  m
                public int compare(Pair<FileRef, Long> o1, Pair<FileRef, Long> o2) {
                    if (o1.getSecond() == o2.getSecond())
                        return o1.getFirst().compareTo(o2.getFirst());
                    if (o1.getSecond() < o2.getSecond())
                        return -1;
                    return 1;
                }
            });

    for (Iterator<Entry<FileRef, DataFileValue>> iterator = filesToCompact.entrySet().iterator(); iterator
            .hasNext();) {
        Entry<FileRef, DataFileValue> entry = iterator.next();
        fileHeap.add(new Pair<FileRef, Long>(entry.getKey(), entry.getValue().getSize()));
    }

    Set<FileRef> smallestFiles = new HashSet<FileRef>();
    while (smallestFiles.size() < maxFilesToCompact && fileHeap.size() > 0) {
        Pair<FileRef, Long> pair = fileHeap.remove();
        filesToCompact.remove(pair.getFirst());
        smallestFiles.add(pair.getFirst());
    }

    return smallestFiles;
}