package ru.kuznec;

import org.apache.ignite.IgniteException;
import org.apache.ignite.compute.ComputeJob;

public class MatrixMinJob implements ComputeJob {
    private final int[][] matrix;
    private final int startRow;
    private final int endRow;

    public MatrixMinJob(int[][] matrix, int startRow, int endRow) {
        this.matrix = matrix;
        this.startRow = startRow;
        this.endRow = endRow;
    }

    @Override
    public Object execute() throws IgniteException {
        int localMin = Integer.MAX_VALUE;

        for (int i = startRow; i < endRow; i++) {
            for (int j = 0; j < i && j < matrix[i].length; j++) {
                localMin = Math.min(localMin, matrix[i][j]);
            }
        }
        return localMin;
    }

    @Override
    public void cancel() {}
}