it.unimi.dsi.mg4j.util
Class ScoredDocumentBoundedSizeQueue

java.lang.Object
  extended byit.unimi.dsi.mg4j.util.ScoredDocumentBoundedSizeQueue

public class ScoredDocumentBoundedSizeQueue
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 removing those that are first w.r.t. the secondary comparator. In particular, using the constructor with implicit comparators will give a queue that remembers just the documents with highest score.

Note that the accessible arrays document and score contain the document and scores corresponding to the indices returned by DoubleHeapSesquiIndirectDoublePriorityQueue.dequeue().


Field Summary
 int[] document
          An array containing documents.
 double[] score
          An array containing document scores.
 
Constructor Summary
ScoredDocumentBoundedSizeQueue(int capacity)
          Creates a new empty bounded-size queue with a given capacity and natural order as primary comparator.
ScoredDocumentBoundedSizeQueue(int capacity, DoubleComparator c)
          Creates a new empty bounded-size queue with a given capacity.
 
Method Summary
 int dequeue()
          Dequeues an index from the queue.
 void enqueue(int d, double s)
          Enqueues a document with given score.
 boolean isEmpty()
           
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

score

public final double[] score
An array containing document scores.


document

public final int[] document
An array containing documents.

Constructor Detail

ScoredDocumentBoundedSizeQueue

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

This constructor uses as secondary comparator the opposite of the natural order.

Parameters:
capacity - the initial capacity of this queue.

ScoredDocumentBoundedSizeQueue

public ScoredDocumentBoundedSizeQueue(int capacity,
                                      DoubleComparator c)
Creates a new empty bounded-size queue with a given capacity.

Parameters:
capacity - the initial capacity of this queue.
c - the comparator used in this queue, or null for the natural order.
Method Detail

enqueue

public void enqueue(int d,
                    double s)
Enqueues a document with given score.

Parameters:
d - the document to enqueue.
s - its score.

isEmpty

public boolean isEmpty()

size

public int size()

dequeue

public int dequeue()
Dequeues an index from the queue. The actual document and score may be retrieved by peeking into document and score using the index returned by this method. Documents are dequeued in inverse score order.

Returns:
the next index to be dequeued.