Class ScoredDocumentBoundedSizeQueue<T>


  • public class ScoredDocumentBoundedSizeQueue<T>
    extends Object
    A queue of scored documents with fixed maximum capacity.

    Instances of this class contain a queue in which it possible to enqueue a document with given score. The capacity of the queue is fixed at creation time: once the queue is filled, new elements are enqueued by dequeueing those in the queue or discarded, depending on their score; the return value of enqueue(long, double, Object) can be used to check whether the argument has been actually enqueued or not. In particular, using the standard constructor will give a queue that remembers just the documents with highest score. As a commodity, document can be enqueued together with additional information that can be retrieved later.

    The standard constructor orders document by score first, and then by document index. This trick guarantees that the queue is stable (because the order is an actual order, not a preorder), and makes it possible to consistently retrieve documents from the k-th to the (k+j)-th using a queue of capacity k+j from which j elements are extracted.

    Warning: documents are dequeued in score order, which means documents with smaller score are dequeued first.

    The queue returns its results as instances of DocumentScoreInfo.

    • Constructor Detail

      • ScoredDocumentBoundedSizeQueue

        public ScoredDocumentBoundedSizeQueue​(int capacity)
        Creates a new empty bounded-size queue with a given capacity and natural order as comparator.

        Documents with equal scores will be compared using their document index.

        Parameters:
        capacity - the initial capacity of this queue.
    • Method Detail

      • wouldEnqueue

        public boolean wouldEnqueue​(int d,
                                    double s)
        Checks whether a document with given score would be enqueued.

        If this methods returns true, an immediately following call to enqueue(long, double, Object) with the same score would case the document to be enqueued.

        Parameters:
        d - the document to test.
        s - its score.
        Returns:
        true if the document would have been enqueued by enqueue(long, double, Object).
      • enqueue

        public boolean enqueue​(long document,
                               double s,
                               T i)
        Enqueues a document with given score and info.
        Parameters:
        document - the document to enqueue.
        s - its score.
        i - additional information about this document.
        Returns:
        true if the document has been actually enqueued.
      • enqueue

        public boolean enqueue​(long document,
                               double s)
        Enqueues a document with given score.
        Parameters:
        document - the document to enqueue.
        s - its score.
        Returns:
        true if the document has been actually enqueued.
      • isEmpty

        public boolean isEmpty()
      • size

        public int size()