ValueIterator - An iterator over intermediate values for use with mapreduce - MATLAB (original) (raw)
Main Content
An iterator over intermediate values for use with mapreduce
Description
The mapreduce
function automatically creates aValueIterator
object during execution and uses it to store the values associated with each unique intermediate key added by the map function. Although you never need to explicitly create a ValueIterator
object to usemapreduce
, you do need to interact with this object in the reduce function. Use the hasnext
and getnext
object functions to retrieve the values associated with each unique key in the intermediate KeyValueStore
object.
Creation
The mapreduce
function automatically createsValueIterator
objects during execution.
Properties
Key
— Intermediate key
numeric scalar | character vector
This property is read-only.
Intermediate key, specified as a numeric scalar or character vector.Key
is one of the unique keys added by a map function. All the values in the ValueIterator
object are associated with this key.
Object Functions
hasnext | Determine if ValueIterator has one or more values available |
---|---|
getnext | Get next value from ValueIterator |
Examples
Get Values from ValueIterator in Reduce Function
Use the hasnext
and getnext
functions in a while
loop within the reduce function to iteratively get values from the ValueIterator
. For example,
function MeanDistReduceFun(sumLenKey, sumLenIter, outKVStore) sumLen = [0, 0]; while hasnext(sumLenIter) sumLen = sumLen + getnext(sumLenIter); end add(outKVStore, 'Mean', sumLen(1)/sumLen(2)); end
Always call hasnext
before getnext
to confirm availability of a value. mapreduce
returns an error if you call getnext
with no remaining values in theValueIterator
.
Version History
Introduced in R2014b