private void setCell(int i,int j) {
        Cell thisCell=thisRow[i];
        Cell left=thisRow[i-1];
        Cell above=previousRow[i];
        Cell leftAbove=previousRow[i-1];

        boolean substitution=!query[i-1].equals(field[j-1]);

        int leftCost=left.getTotal()+1;
        int aboveCost=above.getTotal()+1;
        int leftAboveCost=leftAbove.getTotal() + ( substitution ? 1 : 0 );

        if (leftCost<=aboveCost && leftCost<=leftAboveCost) {
            thisCell.setTo(left);
            thisCell.addDeletion();
        }
        else if (aboveCost<=leftCost && aboveCost<=leftAboveCost) {
            thisCell.setTo(above);
            thisCell.addInsertion();
        }
        else {
            thisCell.setTo(leftAbove);
            if (substitution)
                thisCell.addSubstitution();
        }

        if (i>1 && j>1 && query[i-1].equals(field[j-2]) && query[i-2].equals(field[j-1]) ) {
            Cell twoAboveAndLeft=previousPreviousRow[i-2];
            int transpositionCost= + ( substitution ? 1 : 0);
            if (transpositionCost<thisCell.getTotal()) {
                thisCell.setTo(twoAboveAndLeft);
                thisCell.addTransposition();
            }
        }
    }
The cell containg the last calculated edit distance
searchlib/src/test/java/com/yahoo/searchlib/ranking/features/fieldmatch/reference/OptimalStringAlignmentDistance.java