src/main/java/eu/digitisation/distance/ArrayEditDistance.java
public static <Type> int DL(Type[] first, Type[] second) {
        int i, j;
        int[][] A;

        // intialize
        A = new int[3][second.length+ 1];

        // Compute first row
        A[0][0] = 0;
        for (j = 1; j <= second.length; ++j) {
            A[0][j] = A[0][j - 1] + 1;
        }

        // Compute other rows
        for (i = 1; i <= first.length; ++i) {
            A[i % 3][0] = A[(i - 1) % 3][0] + 1;
            for (j = 1; j <= second.length; ++j) {
                if (first[i - 1] == second[j - 1]) {
                    A[i % 3][j] = A[(i - 1) % 3][j - 1];
                } else {
                    if (i > 1 && j > 1
                            && first[i - 1] == second[j - 2]
                            && first[i - 2] == second[j - 1]) {
                        A[i % 3][j] = min(A[(i - 1) % 3][j] + 1,
                                A[i % 3][j - 1] + 1,
                                A[(i - 2) % 3][j - 2] + 1);
                    } else {
                        A[i % 3][j] = min(A[(i - 1) % 3][j] + 1,
                                A[i % 3][j - 1] + 1,
                                A[(i - 1) % 3][j - 1] + 1);
                    }
                }
            }
        }
        return A[first.length % 3][second.length];
    }
/**
     * @param <Type>
     * @param first the first array.
     * @param second the second array.
     * @return the Damerau-Levenshtein distance between first and second.
     */
@param 
@param first the first array.
@param second the second array.
@return the Damerau-Levenshtein distance between first and second.
@param @param first the first array . @param second the second array . @return the Damerau - Levenshtein distance between first and second .
public static <Type> int DL(Type[] first, Type[] second) {
        int i, j;
        int[][] A;
        A = new int[3][second.length+ 1];
        A[0][0] = 0;
        for (j = 1; j <= second.length; ++j) {
            A[0][j] = A[0][j - 1] + 1;
        }
        for (i = 1; i <= first.length; ++i) {
            A[i % 3][0] = A[(i - 1) % 3][0] + 1;
            for (j = 1; j <= second.length; ++j) {
                if (first[i - 1] == second[j - 1]) {
                    A[i % 3][j] = A[(i - 1) % 3][j - 1];
                } else {
                    if (i > 1 && j > 1
                            && first[i - 1] == second[j - 2]
                            && first[i - 2] == second[j - 1]) {
                        A[i % 3][j] = min(A[(i - 1) % 3][j] + 1,
                                A[i % 3][j - 1] + 1,
                                A[(i - 2) % 3][j - 2] + 1);
                    } else {
                        A[i % 3][j] = min(A[(i - 1) % 3][j] + 1,
                                A[i % 3][j - 1] + 1,
                                A[(i - 1) % 3][j - 1] + 1);
                    }
                }
            }
        }
        return A[first.length % 3][second.length];
    }
public static < Type > int DL ( Type [ ] first , Type [ ] second ) { int i , j ; int [ ] [ ] A ; A = new int [ 3 ] [ second . length + 1 ] ; A [ 0 ] [ 0 ] = 0 ; for ( j = 1 ; j <= second . length ; ++ j ) { A [ 0 ] [ j ] = A [ 0 ] [ j - 1 ] + 1 ; } for ( i = 1 ; i <= first . length ; ++ i ) { A [ i % 3 ] [ 0 ] = A [ ( i - 1 ) % 3 ] [ 0 ] + 1 ; for ( j = 1 ; j <= second . length ; ++ j ) { if ( first [ i - 1 ] == second [ j - 1 ] ) { A [ i % 3 ] [ j ] = A [ ( i - 1 ) % 3 ] [ j - 1 ] ; } else { if ( i > 1 && j > 1 && first [ i - 1 ] == second [ j - 2 ] && first [ i - 2 ] == second [ j - 1 ] ) { A [ i % 3 ] [ j ] = min ( A [ ( i - 1 ) % 3 ] [ j ] + 1 , A [ i % 3 ] [ j - 1 ] + 1 , A [ ( i - 2 ) % 3 ] [ j - 2 ] + 1 ) ; } else { A [ i % 3 ] [ j ] = min ( A [ ( i - 1 ) % 3 ] [ j ] + 1 , A [ i % 3 ] [ j - 1 ] + 1 , A [ ( i - 1 ) % 3 ] [ j - 1 ] + 1 ) ; } } } } return A [ first . length % 3 ] [ second . length ] ; }
@param <Type>
 @param first the first array.
@param <Type > @param first the first array .
// intialize // Compute first row // Compute other rows