function varargout = hGlobalIndicesImpl(dist, dim, workerIdx)
%hGlobalIndicesImpl The implementation of global indices without the error checking.
%
%   See also codistributor1d/globalIndices.

%   Copyright 2007-2022 The MathWorks, Inc.

part = dist.Partition;

if dim == dist.Dimension
    [varargout{1:nargout}] = partitionIndices(part, workerIdx);
    return;
end

% We only arrive here if the dimension is not equal to the distribution
% dimension.  
gSize = dist.Cached.GlobalSize;
if dim > length(gSize)
    dimSize = 1;
else
    dimSize = gSize(dim);
end

if nargout <= 1
    varargout{1} = 1:dimSize;
elseif nargout == 2
    varargout{1} = 1;
    varargout{2} = dimSize;
else
    error(message('parallel:codistributors:c1dGlobalIndicesImplTooManyOutputArguments'));
end

end % End of hGlobalIndicesImpl.
