Skip to content

Commit

Permalink
Fixed: incorrect serialization of empty hashtables (manifested itself…
Browse files Browse the repository at this point in the history
… for larger k values).
  • Loading branch information
agudys committed May 24, 2019
1 parent b27bc87 commit 8761a5f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
56 changes: 30 additions & 26 deletions src/prefix_kmer_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,24 +475,26 @@ void PrefixKmerDb::serialize(std::ofstream& file, bool rawHashtables) const {
temp = ht.get_size();
file.write(reinterpret_cast<const char*>(&temp), sizeof(temp));

// write ht elements in portions
size_t bufpos = 0;
for (auto it = ht.cbegin(); it < ht.cend(); ++it) {
if (ht.is_free(*it)) {
continue;
}
if (temp > 0) {
// write ht elements in portions
size_t bufpos = 0;
for (auto it = ht.cbegin(); it < ht.cend(); ++it) {
if (ht.is_free(*it)) {
continue;
}

hashtableBuffer[bufpos++] = *it;
if (bufpos == numHastableElements) {
file.write(reinterpret_cast<const char*>(&bufpos), sizeof(size_t));
file.write(buffer, bufpos * sizeof(hash_map_lp<suffix_t, pattern_id_t>::item_t));
bufpos = 0;
hashtableBuffer[bufpos++] = *it;
if (bufpos == numHastableElements) {
file.write(reinterpret_cast<const char*>(&bufpos), sizeof(size_t));
file.write(buffer, bufpos * sizeof(hash_map_lp<suffix_t, pattern_id_t>::item_t));
bufpos = 0;
}
}
}

// write remaining ht elements
file.write(reinterpret_cast<const char*>(&bufpos), sizeof(size_t));
file.write(buffer, bufpos * sizeof(hash_map_lp<suffix_t, pattern_id_t>::item_t));
// write remaining ht elements
file.write(reinterpret_cast<const char*>(&bufpos), sizeof(size_t));
file.write(buffer, bufpos * sizeof(hash_map_lp<suffix_t, pattern_id_t>::item_t));
}
}
}

Expand Down Expand Up @@ -588,20 +590,22 @@ bool PrefixKmerDb::deserialize(std::ifstream& file) {
// load ht size
file.read(reinterpret_cast<char*>(&temp), sizeof(temp));

// load ht elements
ht.clear();
ht.reserve_for_additional(temp);
if (temp > 0) {
// load ht elements
ht.clear();
ht.reserve_for_additional(temp);

size_t readCount = 0;
while (readCount < temp) {
size_t portion = 0;
file.read(reinterpret_cast<char*>(&portion), sizeof(size_t));
file.read(buffer, portion * sizeof(hash_map_lp<suffix_t, pattern_id_t>::item_t));
size_t readCount = 0;
while (readCount < temp) {
size_t portion = 0;
file.read(reinterpret_cast<char*>(&portion), sizeof(size_t));
file.read(buffer, portion * sizeof(hash_map_lp<suffix_t, pattern_id_t>::item_t));

for (size_t j = 0; j < portion; ++j) {
ht.insert(hashtableBuffer[j].key, hashtableBuffer[j].val);
for (size_t j = 0; j < portion; ++j) {
ht.insert(hashtableBuffer[j].key, hashtableBuffer[j].val);
}
readCount += portion;
}
readCount += portion;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/version.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once

#define VERSION "1.6.1"
#define DATE "22.05.2019"
#define VERSION "1.6.2"
#define DATE "24.05.2019"

0 comments on commit 8761a5f

Please sign in to comment.