galois.objects
Class Mappables

java.lang.Object
  extended by galois.objects.Mappables

public class Mappables
extends Object

Several helper methods to bridge common Java classes into Mappable framework.


Constructor Summary
Mappables()
           
 
Method Summary
static
<T> Mappable<T>
fromList(List<T> list)
          Creates a mappable view from a list.
static Mappable<String> fromReader(BufferedReader reader)
          Creates a mappable over lines of a stream.
static
<A,B> Mappable<Pair<A,B>>
product(Mappable<A> rows, Lambda<A,Mappable<B>> cols)
          Forms the product space between two Mappables.
static Mappable<Integer> range(int start, int end)
          Creates a mappable over integers in a range.
static Mappable<Integer> range(int start, int end, int chunkSize)
          Creates a mappable over integers in a range.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Mappables

public Mappables()
Method Detail

product

public static <A,B> Mappable<Pair<A,B>> product(Mappable<A> rows,
                                                Lambda<A,Mappable<B>> cols)
Forms the product space between two Mappables. This is useful for flattening nested iterators into a single iterator. Product iteration proceeds by row, completing an entire row before moving on to the next row. During concurrent execution, entire rows are processed concurrently. The pair objects produced by this mappable are reused between iterations. Therefore, it is an error to store references to the argument pairs; make a copy instead.

Type Parameters:
A - type of first component of the product space
B - type of second component of the product space
Parameters:
rows - mappable that iterates over first component of the product space
cols - function that generates a mappable over the second component of the product space from an element of the first component
Returns:
a mappable over the product space

fromReader

public static Mappable<String> fromReader(BufferedReader reader)
Creates a mappable over lines of a stream. Once iteration is complete, the stream is closed and further use of the mappable will be invalid.

Parameters:
reader - reader of stream
Returns:
a mappable instance over lines of a stream

range

public static Mappable<Integer> range(int start,
                                      int end)
Creates a mappable over integers in a range.

Parameters:
start - starting integer
end - ending integer (exclusive)
Returns:
a mappable over [start, end)

range

public static Mappable<Integer> range(int start,
                                      int end,
                                      int chunkSize)
Creates a mappable over integers in a range. Integers are given out in chunkSize size blocks.

Parameters:
start - starting integer
end - ending integer (exclusive)
chunkSize - the chunk size
Returns:
a mappable over [start, end)

fromList

public static <T> Mappable<T> fromList(List<T> list)
Creates a mappable view from a list. Behavior is undefined if the backing list is modified during iteration.

Type Parameters:
T - type of elements of the list
Parameters:
list - list that this mappable is a view of
Returns:
a mappable view of the given list