I'm trying to compare two directories having about 15k files each for any changes. A is the newer version and B must be updated to it.
I have two large checksum list files, call them A and B. A is newer and B is an older version. Each have about 15k entries that look sort of like the following :
<entry1 -filepath> <entry1 -checksum>
<entry2 -filepath> <entry2 -checksum>
<entry3 -filepath> <entry3 -checksum>
. .
. .
. .
The entries are listed in alphabetical order. The two files need to be compared to check the following :
1. Two entries have the same file path but different checksums.
2. An entry exists in file A but not in file B.
3. An entry exists in file B but not in file A.
My proposal 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 of doing this? Am I doing something wrong here?
If anyone sees an XY problem, just let me know and I will fill in the background.