galois.runtime.wl
Class ChunkedFIFO<T>

java.lang.Object
  extended by galois.runtime.wl.ChunkedFIFO<T>
Type Parameters:
T - the type of elements of the worklist
All Implemented Interfaces:
Worklist<T>

public class ChunkedFIFO<T>
extends Object
implements Worklist<T>

Order elements in chunks of size N, full chunks are ordered in FIFO order. Partial chunks are unordered with respect to each other. Elements are unordered within a chunk and are eligible to be ordered by subsequent rules.

See Also:
ChunkedLIFO, FIFO

Field Summary
static int DEFAULT_CHUNK_SIZE
           
 
Constructor Summary
ChunkedFIFO(int chunkSize, Maker<T> maker, boolean needSize)
          Creates a chunked FIFO order with the given chunk size
ChunkedFIFO(Maker<T> maker, boolean needSize)
          Creates a chunked FIFO order with the default chunk size (32)
 
Method Summary
 void add(T item, ForeachContext<T> ctx)
          Adds an element to this worklist.
 void addInitial(T item, ForeachContext<T> ctx)
          Adds an element to this worklist.
 void finishAddInitial()
          Marks when no more elements will be added from the initial elements passed to an executor.
 boolean isEmpty()
          Checks for emptiness.
 Worklist<T> newInstance()
           
 T poll(ForeachContext<T> ctx)
          Removes an element from this worklist.
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CHUNK_SIZE

public static final int DEFAULT_CHUNK_SIZE
See Also:
Constant Field Values
Constructor Detail

ChunkedFIFO

public ChunkedFIFO(Maker<T> maker,
                   boolean needSize)
Creates a chunked FIFO order with the default chunk size (32)


ChunkedFIFO

public ChunkedFIFO(int chunkSize,
                   Maker<T> maker,
                   boolean needSize)
Creates a chunked FIFO order with the given chunk size

Parameters:
chunkSize - chunk size to use
Method Detail

newInstance

public Worklist<T> newInstance()
Specified by:
newInstance in interface Worklist<T>
Returns:
a new, empty instance of this worklist

add

public void add(T item,
                ForeachContext<T> ctx)
Description copied from interface: Worklist
Adds an element to this worklist. This method is used for newly generated elements or elements added during Galois execution. Thread-safe.

Specified by:
add in interface Worklist<T>
Parameters:
item - the item to add
ctx - an executor context

addInitial

public void addInitial(T item,
                       ForeachContext<T> ctx)
Description copied from interface: Worklist
Adds an element to this worklist. This method is used when adding elements from the initial elements passed to an executor. Thread-safe.

Specified by:
addInitial in interface Worklist<T>
Parameters:
item - the item to add
ctx - an executor context

poll

public T poll(ForeachContext<T> ctx)
Description copied from interface: Worklist
Removes an element from this worklist. Thread-safe.

Specified by:
poll in interface Worklist<T>
Parameters:
ctx - an executor context
Returns:
an element or null if there are no more elements in this worklist

isEmpty

public boolean isEmpty()
Description copied from interface: Worklist
Checks for emptiness. Only called by one thread at a time so does not have to be thread-safe. Also, can assume that all threads have had Worklist.poll(ForeachContext) return null.

Specified by:
isEmpty in interface Worklist<T>
Returns:
true if there are no more elements in this worklist

size

public int size()
Specified by:
size in interface Worklist<T>
Returns:
the number of elements in this worklist, during concurrent execution this may be a lower bound on the number of elements

finishAddInitial

public void finishAddInitial()
Description copied from interface: Worklist
Marks when no more elements will be added from the initial elements passed to an executor.

Specified by:
finishAddInitial in interface Worklist<T>