galois.runtime.wl
Class RandomPermutation<T>

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

@OnlyLeaf
public class RandomPermutation<T>
extends Object
implements Worklist<T>

Order elements according to a random permutation of initial elements. Elements are ordered randomly with respect to each other. After this worklist is initialized, no additional elements may be added to this worklist. If elements need to be added during iteration, consider RandomOrder or ChunkedRandomOrder.

See Also:
RandomOrder, ChunkedRandomOrder

Constructor Summary
RandomPermutation(Maker<T> maker, boolean needSize)
           
 
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
 

Constructor Detail

RandomPermutation

public RandomPermutation(Maker<T> maker,
                         boolean needSize)
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

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>

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