Main Content

ValueIterator

用于 mapreduce 的中间值迭代器

说明

mapreduce 函数在执行期间自动创建 ValueIterator 对象,并使用它存储与 map 函数添加的每个唯一中间键关联的值。尽管您绝不需要显式创建 ValueIterator 对象以使用 mapreduce,但您需要在 reduce 函数中与此对象交互。使用 hasnextgetnext 对象函数检索与中间 KeyValueStore 对象中的每个唯一键关联的值。

创建对象

mapreduce 函数在执行期间自动创建 ValueIterator 对象。

属性

全部展开

此 属性 为只读。

中间键,指定为数值标量或字符向量。Key 是 map 函数添加的一个唯一键。ValueIterator 对象中的所有值都与此键关联。

对象函数

hasnext确定 ValueIterator 是否具有一个或多个可用值
getnext从 ValueIterator 获取下一个值

示例

全部折叠

在 reduce 函数内的 while 循环中使用 hasnextgetnext 函数,以便从 ValueIterator 以迭代方式获取值。例如,

function MeanDistReduceFun(sumLenKey, sumLenIter, outKVStore)
    sumLen = [0, 0];
    while hasnext(sumLenIter)
        sumLen = sumLen + getnext(sumLenIter);
    end
    add(outKVStore, 'Mean', sumLen(1)/sumLen(2));
end

始终在 getnext 之前调用 hasnext 以确认值的可用性。如果调用 getnext 而没有 ValueIterator 中的其余值,则 mapreduce 返回错误。

版本历史记录

在 R2014b 中推出