Iterators

Many low level algorithms rely on an iterator to break a collection into smaller pieces. Each piece is processed by a block. For very large BATs it may make sense to break it into chunks and process them separately to solve a query. An iterator pair is provided to chop a BAT into fixed size elements. Each chunk is made available as a view. It provides read-only access to an underlying BAT. Adjusting the bounds is cheap, once the view descriptor has been constructed.

The smallest granularity is a single (oid,value) pair, which can be used to realize an iterator over the individual BAT elements. For larger sized chunks, the operators return a view.

All iterators require storage space to administer the location of the next element. The BAT iterator module uses a simple lng variable, which also acts as a cursor for barrier statements.

MODULE iterator;

PATTERN iterator.new(X_0:bat[:any_2]) (X_1:oid, X_2:any_2);
COMMENT "Process the buns one by one extracted from a void table.";

COMMAND iterator.new(X_0:bat[:any_2], X_1:lng) (X_2:lng, X_3:bat[:any_2]);
COMMENT "Create an iterator with fixed granule size.\nThe result is a view.";

PATTERN iterator.next(X_0:bat[:any_2]) (X_1:oid, X_2:any_2);
COMMENT "Produce the next bun for processing.";

COMMAND iterator.next(X_0:bat[:any_2], X_1:lng) (X_2:lng, X_3:bat[:any_2]);
COMMENT "Produce the next chunk for processing.";

COMMAND iterator.next(X_0:dbl, X_1:dbl):dbl;
COMMENT "Advances the iterator with a fixed value";

COMMAND iterator.next(X_0:flt, X_1:flt):flt;
COMMENT "";

COMMAND iterator.next(X_0:int, X_1:int):int;
COMMENT "";

COMMAND iterator.next(X_0:lng, X_1:lng):lng;
COMMENT "";

COMMAND iterator.next(X_0:oid, X_1:oid):oid;
COMMENT "";

COMMAND iterator.next(X_0:sht, X_1:sht):sht;
COMMENT "";