Class FastQueue<T>

java.lang.Object
org.antlr.runtime.misc.FastQueue<T>
Direct Known Subclasses:
LookaheadStream

public class FastQueue<T> extends Object
A queue that can dequeue and get(i) in O(1) and grow arbitrarily large. A linked list is fast at dequeue but slow at get(i). An array is the reverse. This is O(1) for both operations. List grows until you dequeue last element at end of buffer. Then it resets to start filling at 0 again. If adds/removes are balanced, the buffer will not grow too large. No iterator stuff as that's not how we'll use it.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected List<T>
    dynamically-sized buffer of elements
    protected int
    index of next element to fill
    protected int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(T o)
     
    void
     
    elementAt(int i)
    Return element i elements ahead of current element.
     
    int
     
    Get and remove first element in queue
    void
     
    int
     
    Return string of current buffer contents; non-destructive

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • data

      protected List<T> data
      dynamically-sized buffer of elements
    • p

      protected int p
      index of next element to fill
    • range

      protected int range
  • Constructor Details

    • FastQueue

      public FastQueue()
  • Method Details

    • reset

      public void reset()
    • clear

      public void clear()
    • remove

      public T remove()
      Get and remove first element in queue
    • add

      public void add(T o)
    • size

      public int size()
    • range

      public int range()
    • head

      public T head()
    • elementAt

      public T elementAt(int i)
      Return element i elements ahead of current element. i==0 gets current element. This is not an absolute index into data since p defines the start of the real list.
    • toString

      public String toString()
      Return string of current buffer contents; non-destructive
      Overrides:
      toString in class Object