it.unimi.dsi.fastutil
Interface IndirectPriorityQueue<K>

All Known Subinterfaces:
ByteIndirectPriorityQueue, CharIndirectPriorityQueue, DoubleIndirectPriorityQueue, FloatIndirectPriorityQueue, IntIndirectPriorityQueue, LongIndirectPriorityQueue, ShortIndirectPriorityQueue
All Known Implementing Classes:
AbstractIndirectPriorityQueue, ByteArrayIndirectPriorityQueue, ByteHeapIndirectPriorityQueue, ByteHeapSemiIndirectPriorityQueue, CharArrayIndirectPriorityQueue, CharHeapIndirectPriorityQueue, CharHeapSemiIndirectPriorityQueue, DoubleArrayIndirectPriorityQueue, DoubleHeapIndirectPriorityQueue, DoubleHeapSemiIndirectPriorityQueue, FloatArrayIndirectPriorityQueue, FloatHeapIndirectPriorityQueue, FloatHeapSemiIndirectPriorityQueue, IndirectPriorityQueues.EmptyIndirectPriorityQueue, IndirectPriorityQueues.SynchronizedIndirectPriorityQueue, IntArrayIndirectPriorityQueue, IntHeapIndirectPriorityQueue, IntHeapSemiIndirectPriorityQueue, LongArrayIndirectPriorityQueue, LongHeapIndirectPriorityQueue, LongHeapSemiIndirectPriorityQueue, ObjectArrayIndirectPriorityQueue, ObjectHeapIndirectPriorityQueue, ObjectHeapSemiIndirectPriorityQueue, ShortArrayIndirectPriorityQueue, ShortHeapIndirectPriorityQueue, ShortHeapSemiIndirectPriorityQueue

public interface IndirectPriorityQueue<K>

An indirect priority queue.

An indirect priority queue provides a way to enqueue by index elements taken from a given reference list, and to dequeue them in some specified order. Elements that are smaller in the specified order are dequeued first. It is also possible to get the index of the first element, that is, the index that would be dequeued next.

Additionally, the queue may provide a method to peek at the index of the element that would be dequeued last.

The reference list should not change during queue operations (or, more precisely, the relative order of the elements corresponding to indices in the queue should not change). Nonetheless, some implementations may give the caller a way to notify the queue that the first element has changed its relative position in the order.

Optionally, an indirect priority queue may even provide methods to notify the change of any element of the reference list, to check the presence of an index in the queue, and to remove an index from the queue. It may even allow to notify that all elements have changed.

It is always possible to enqueue two distinct indices corresponding to equal elements of the reference list. However, depending on the implementation, it may or may not be possible to enqueue twice the same index.

Note that all element manipulation happens via indices.


Method Summary
 void allChanged()
          Notifies this queue that the all elements have changed (optional operation).
 void changed()
          Notifies this queue that the first element has changed (optional operation).
 void changed(int index)
          Notifies this queue that the specified element has changed (optional operation).
 void clear()
          Removes all elements from this queue.
 java.util.Comparator<? super K> comparator()
          Returns the comparator associated with this queue, or null if it uses its elements' natural ordering.
 boolean contains(int index)
          Checks whether a given index belongs to this queue (optional operation).
 int dequeue()
          Dequeues the first element from this queue.
 void enqueue(int index)
          Enqueues a new element.
 int first()
          Returns the first element of this queue.
 int front(int[] a)
          Retrieves the front of this queue in a given array (optional operation).
 boolean isEmpty()
          Checks whether this queue is empty.
 int last()
          Returns the last element of this queue, that is, the element the would be dequeued last (optional operation).
 boolean remove(int index)
          Removes the specified element from this queue (optional operation).
 int size()
          Returns the number of elements in this queue.
 

Method Detail

enqueue

void enqueue(int index)
Enqueues a new element.

Parameters:
index - the element to enqueue..

dequeue

int dequeue()
Dequeues the first element from this queue.

Returns:
the dequeued element.
Throws:
java.util.NoSuchElementException - if this queue is empty.

isEmpty

boolean isEmpty()
Checks whether this queue is empty.

Returns:
true if this queue is empty.

size

int size()
Returns the number of elements in this queue.

Returns:
the number of elements in this queue.

clear

void clear()
Removes all elements from this queue.


first

int first()
Returns the first element of this queue.

Returns:
the first element.
Throws:
java.util.NoSuchElementException - if this queue is empty.

last

int last()
Returns the last element of this queue, that is, the element the would be dequeued last (optional operation).

Returns:
the last element.
Throws:
java.util.NoSuchElementException - if this queue is empty.

changed

void changed()
Notifies this queue that the first element has changed (optional operation).


comparator

java.util.Comparator<? super K> comparator()
Returns the comparator associated with this queue, or null if it uses its elements' natural ordering.

Returns:
the comparator associated with this sorted set, or null if it uses its elements' natural ordering.

changed

void changed(int index)
Notifies this queue that the specified element has changed (optional operation).

Note that the specified element must belong to this queue.

Parameters:
index - the element that has changed.
Throws:
java.util.NoSuchElementException - if the specified element is not in this queue.

allChanged

void allChanged()
Notifies this queue that the all elements have changed (optional operation).


contains

boolean contains(int index)
Checks whether a given index belongs to this queue (optional operation).

Returns:
true if the specified index belongs to this queue.

remove

boolean remove(int index)
Removes the specified element from this queue (optional operation).

Parameters:
index - the element to be removed.
Returns:
true if the index was in the queue.

front

int front(int[] a)
Retrieves the front of this queue in a given array (optional operation).

The front of an indirect queue is the set of indices whose associated elements in the reference array are equal to the element associated to the first index. These indices can be always obtain by dequeueing, but this method should retrieve efficiently such indices in the given array without modifying the state of this queue.

Parameters:
a - an array large enough to hold the front (e.g., at least long as the reference array).
Returns:
the number of elements actually written (starting from the first position of a).