Java efficiency when comparing large checksums

I am trying to compare two directories with about 15 thousand files for any changes. A is a newer version, and B needs to be updated to it.

I have two large checksum list files, name them A and B. A is newer and B is an older version. Each of them contains about 15 thousand notes, which look something like this:

<entry1 -filepath> <entry1 -checksum>
<entry2 -filepath> <entry2 -checksum>
<entry3 -filepath> <entry3 -checksum>
.                  .
.                  .
.                  .

Entries are listed in alphabetical order. These two files must be compared to verify the following:

1. Two entries have the same file path, but different checksums.
2. The record exists in file A, but not in file B.
3. The record exists in file B, but not in file A.

My suggestion algorithm:

int currentBLine = -1;

for(int index = 0; index < A.length; index++)
{
    String newfilepath = A[index].getFilePath();
    String newchecksum = A[index].getCheckSum();

    for(; currentBLine < B.length; currentBLine++)
    {
        String oldfilepath = B[currentBLine].getFilePath();
        String oldchecksum = B[currentBLine].getCheckSum();

        if(filepath.compareTo(oldfilepath) > 0)
        {
            deleteFile(oldfilepath);
        }
        else if(filepath.compareTo(oldfilepath) == 0)
        {
            if(checksum.equals(oldchecksum)
            {
                currentBLine++;
                break;
            }
            else
            {
                updateFile(oldfilepath, newfilepath);
                break;
            }
        }
        else
        {
            createFile(newfilepath);
            break;
        }
    }
}

Is this the most efficient way to do this? Am I something wrong here?

- XY, , .

+4
1

, ( break ), . , , : , , .

, . , , if , . , break, A B . A B, , . A, B. B, A. , .

+1

All Articles