Top Description Fields Constructors Methods
org.antlr.runtime.misc

public Class FastQueue<T>

extends Object
Class Inheritance
Known Direct Subclasses
org.antlr.runtime.misc.LookaheadStream
Imports
java.util.List, .ArrayList, .NoSuchElementException

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

Modifier and TypeField and Description
protected List<T>
data

dynamically-sized buffer of elements

protected int
p

index of next element to fill

protected int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
add(T o)

public void
public T
elementAt(int i)

Return element i elements ahead of current element.

public T
head()

public int
public T
remove()

Get and remove first element in queue

public void
public int
size()

public String
toString()

Overrides java.lang.Object.toString.

Return string of current buffer contents; non-destructive
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

databack to summary
protected List<T> data

dynamically-sized buffer of elements

pback to summary
protected int p

index of next element to fill

rangeback to summary
protected int range

Constructor Detail

FastQueueback to summary
public FastQueue()

Method Detail

addback to summary
public void add(T o)
clearback to summary
public void clear()
elementAtback to summary
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.

headback to summary
public T head()
rangeback to summary
public int range()
removeback to summary
public T remove()

Get and remove first element in queue

resetback to summary
public void reset()
sizeback to summary
public int size()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Return string of current buffer contents; non-destructive

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override