Skip to content

Commit

Permalink
Fix concatdbs for databases that don't end in a null byte
Browse files Browse the repository at this point in the history
  • Loading branch information
milot-mirdita committed Apr 18, 2023
1 parent ea17d30 commit e379831
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/commons/DBConcat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ DBConcat::DBConcat(const std::string &dataFileNameA, const std::string &indexFil

Debug::Progress progress(indexSizeA);
// where the new key numbering of B should start
const bool writeNull = trimRight > 0;
unsigned int maxKeyA = 0;
#pragma omp parallel num_threads(threads)
{
Expand All @@ -85,10 +86,10 @@ DBConcat::DBConcat(const std::string &dataFileNameA, const std::string &indexFil
size_t idB = dbB.getId(newKey);
size_t dataSizeB = std::max(dbB.getEntryLen(idB), trimRight) - trimRight;
if (dataSizeA >= dataSizeB) {
concatWriter->writeData(data, dataSizeA, newKey, thread_idx);
concatWriter->writeData(data, dataSizeA, newKey, thread_idx, writeNull);
}
} else {
concatWriter->writeData(data, dataSizeA, newKey, thread_idx);
concatWriter->writeData(data, dataSizeA, newKey, thread_idx, writeNull);
}
}

Expand Down Expand Up @@ -124,10 +125,10 @@ DBConcat::DBConcat(const std::string &dataFileNameA, const std::string &indexFil
size_t idB = dbA.getId(newKey);
size_t dataSizeA = std::max(dbA.getEntryLen(idB), trimRight) - trimRight;
if (dataSizeB > dataSizeA) {
concatWriter->writeData(data, dataSizeB, newKey, thread_idx);
concatWriter->writeData(data, dataSizeB, newKey, thread_idx, writeNull);
}
} else {
concatWriter->writeData(data, dataSizeB, newKey, thread_idx);
concatWriter->writeData(data, dataSizeB, newKey, thread_idx, writeNull);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/commons/DBConcat.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DBConcat {
DBConcat(const std::string &dataFileNameA, const std::string &indexFileNameA,
const std::string &dataFileNameB, const std::string &indexFileNameB,
const std::string &dataFileNameC, const std::string &indexFileNameC,
unsigned int threads, bool write = true, bool preserveKeysA = false, bool preserveKeysB = false, bool takeLargerEntry = false, size_t trimRight = 1);
unsigned int threads, bool write = true, bool preserveKeysA = false, bool preserveKeysB = false, bool takeLargerEntry = false, size_t trimRight = 0);

~DBConcat();

Expand Down

0 comments on commit e379831

Please sign in to comment.