%MapTaskResult
% A data class that stores the results of a partitioned Map Task.

% Copyright 2014-2016 The MathWorks, Inc.

classdef (Sealed, Hidden) MapTaskResult < parallel.internal.mapreduce.AbstractTaskResult
properties (SetAccess = immutable)
ReduceTaskSizes = []; % A vector of reduce task sizes ordered by ID.
end

methods
% Create a MapTaskResult.
% Syntax:
% result = MapTaskResult()
% result = MapTaskResult(reduceTaskSizes, keyType, valueType)
function obj = MapTaskResult(reduceTaskSizes, varargin)
obj = obj@parallel.internal.mapreduce.AbstractTaskResult(varargin{:});
if nargin
obj.ReduceTaskSizes = reduceTaskSizes;
end
end

% Combine several MapTaskResult instances together.
function output = vertcat(varargin)
import parallel.internal.mapreduce.MapTaskResult;

reduceTaskSizes = [];
for ii = 1:nargin
nextResult = varargin{ii};
if isempty(nextResult) || isempty(nextResult.ReduceTaskSizes)
continue;
elseif isempty(reduceTaskSizes)
reduceTaskSizes = nextResult.ReduceTaskSizes;
else
reduceTaskSizes = reduceTaskSizes + nextResult.ReduceTaskSizes;
end
end

[keyType, valueType] = combineTypes(varargin{:});

output = MapTaskResult(reduceTaskSizes, keyType, valueType);
end
end
end