it.unimi.dsi.fastutil.shorts
Class ShortArrayFIFOQueue

java.lang.Object
  extended by it.unimi.dsi.fastutil.AbstractPriorityQueue<Short>
      extended by it.unimi.dsi.fastutil.shorts.AbstractShortPriorityQueue
          extended by it.unimi.dsi.fastutil.shorts.ShortArrayFIFOQueue
All Implemented Interfaces:
PriorityQueue<Short>, ShortPriorityQueue

public class ShortArrayFIFOQueue
extends AbstractShortPriorityQueue

A type-specific array-based FIFO queue, supporting also deque operations.

Instances of this class represent a FIFO queue using a backing array in a circular way. The array is enlarged as needed, but it is never shrunk. Use the trim() method to reduce its size, if necessary.

This class provides additional methods that implement a deque (double-ended queue).


Field Summary
protected  short[] array
          The backing array.
protected  int end
          The end position in array.
static int INITIAL_CAPACITY
          The standard initial capacity of a queue.
protected  int length
          The current (cached) length of array.
protected  int start
          The start position in array.
 
Constructor Summary
ShortArrayFIFOQueue()
          Creates a new empty queue with standard initial capacity.
ShortArrayFIFOQueue(int capacity)
          Creates a new empty queue with given capacity.
 
Method Summary
 void clear()
          Removes all elements from this queue.
 ShortComparator comparator()
          Returns null (FIFO queues have no comparator).
 short dequeueLastShort()
          Dequeues the last element from the queue.
 short dequeueShort()
          Dequeues the first element from the queue.
 void enqueue(short x)
          Enqueues a new element.
 void enqueueFirst(short x)
          Enqueues a new element as the first element (in dequeuing order) of the queue.
 short firstShort()
          Returns the first element of the queue.
 short lastShort()
          Returns the last element of the queue.
 int size()
          Returns the number of elements in this queue.
 void trim()
          Trims the queue to the smallest possible size.
 
Methods inherited from class it.unimi.dsi.fastutil.shorts.AbstractShortPriorityQueue
dequeue, enqueue, first, last
 
Methods inherited from class it.unimi.dsi.fastutil.AbstractPriorityQueue
changed, isEmpty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface it.unimi.dsi.fastutil.PriorityQueue
changed, isEmpty
 

Field Detail

INITIAL_CAPACITY

public static final int INITIAL_CAPACITY
The standard initial capacity of a queue.

See Also:
Constant Field Values

array

protected short[] array
The backing array.


length

protected int length
The current (cached) length of array.


start

protected int start
The start position in array. It is always strictly smaller than length.


end

protected int end
The end position in array. It is always strictly smaller than length. Might be actually smaller than start because array is used cyclically.

Constructor Detail

ShortArrayFIFOQueue

public ShortArrayFIFOQueue(int capacity)
Creates a new empty queue with given capacity.

Parameters:
capacity - the initial capacity of this queue.

ShortArrayFIFOQueue

public ShortArrayFIFOQueue()
Creates a new empty queue with standard initial capacity.

Method Detail

comparator

public ShortComparator comparator()
Returns null (FIFO queues have no comparator).

Returns:
null.
See Also:
PriorityQueue.comparator()

dequeueShort

public short dequeueShort()
Description copied from interface: ShortPriorityQueue
Dequeues the first element from the queue.

Returns:
the dequeued element.

dequeueLastShort

public short dequeueLastShort()
Dequeues the last element from the queue.

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

enqueue

public void enqueue(short x)
Description copied from interface: ShortPriorityQueue
Enqueues a new element.

Parameters:
x - the element to enqueue.

enqueueFirst

public void enqueueFirst(short x)
Enqueues a new element as the first element (in dequeuing order) of the queue.


firstShort

public short firstShort()
Returns the first element of the queue.

Returns:
the first element of the queue.

lastShort

public short lastShort()
Returns the last element of the queue.

Specified by:
lastShort in interface ShortPriorityQueue
Overrides:
lastShort in class AbstractShortPriorityQueue
Returns:
the last element of the queue.

clear

public void clear()
Description copied from interface: PriorityQueue
Removes all elements from this queue.


trim

public void trim()
Trims the queue to the smallest possible size.


size

public int size()
Description copied from interface: PriorityQueue
Returns the number of elements in this queue.

Returns:
the number of elements in this queue.


Copyright © 2011. All Rights Reserved.