Class ObjectArrayFIFOQueue<K>

java.lang.Object
it.unimi.dsi.fastutil.objects.ObjectArrayFIFOQueue<K>
All Implemented Interfaces:
it.unimi.dsi.fastutil.PriorityQueue<K>, Serializable

public class ObjectArrayFIFOQueue<K> extends Object implements it.unimi.dsi.fastutil.PriorityQueue<K>, Serializable
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 and shrunk as needed. You can use the trim() method to reduce its memory usage, if necessary.

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

See Also:
  • Field Details

    • INITIAL_CAPACITY

      public static final int INITIAL_CAPACITY
      The standard initial capacity of a queue.
      See Also:
    • array

      protected transient K[] array
      The backing array.
    • length

      protected transient int length
      The current (cached) length of array.
    • start

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

      protected transient 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 Details

    • ObjectArrayFIFOQueue

      public ObjectArrayFIFOQueue(int capacity)
      Creates a new empty queue with given capacity.
      Parameters:
      capacity - the initial capacity of this queue.
    • ObjectArrayFIFOQueue

      public ObjectArrayFIFOQueue()
      Creates a new empty queue with standard initial capacity.
  • Method Details

    • comparator

      public Comparator<? super K> comparator()
      Specified by:
      comparator in interface it.unimi.dsi.fastutil.PriorityQueue<K>
    • dequeue

      public K dequeue()
      Specified by:
      dequeue in interface it.unimi.dsi.fastutil.PriorityQueue<K>
    • dequeueLast

      public K dequeueLast()
      Dequeues the last element from the queue.
      Returns:
      the dequeued element.
      Throws:
      NoSuchElementException - if the queue is empty.
    • enqueue

      public void enqueue(K x)
      Specified by:
      enqueue in interface it.unimi.dsi.fastutil.PriorityQueue<K>
    • enqueueFirst

      public void enqueueFirst(K x)
      Enqueues a new element as the first element (in dequeuing order) of the queue.
      Parameters:
      x - the element to enqueue.
    • first

      public K first()
      Specified by:
      first in interface it.unimi.dsi.fastutil.PriorityQueue<K>
    • last

      public K last()
      Specified by:
      last in interface it.unimi.dsi.fastutil.PriorityQueue<K>
    • clear

      public void clear()
      Specified by:
      clear in interface it.unimi.dsi.fastutil.PriorityQueue<K>
    • trim

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

      public int size()
      Specified by:
      size in interface it.unimi.dsi.fastutil.PriorityQueue<K>
    • capacity

      public int capacity()
      Returns the physical capacity of the queue (internal array).
    • toArray

      public K[] toArray()
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object