Skip to content

Commit

Permalink
Merge branch 'tarlocvec_serialize' into 'master'
Browse files Browse the repository at this point in the history
serialize target_location buckets as vectors

See merge request muellan/metacache!7
  • Loading branch information
Funatiq committed Sep 3, 2018
2 parents 3779a53 + e9ed4f6 commit cecb9c2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
30 changes: 27 additions & 3 deletions src/hash_multimap.h
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,8 @@ class hash_multimap
void deserialize(std::istream& is)
{
using len_t = std::uint64_t;
using target_id = typename value_type::target_id_t;
using window_id = typename value_type::window_id_t;

clear();

Expand All @@ -937,17 +939,25 @@ class hash_multimap
reserve_values(nvalues);
reserve_keys(nkeys);

std::vector<target_id> target_id_buf;
std::vector<window_id> window_id_buf;

for(len_t i = 0; i < nkeys; ++i) {
key_type key;
bucket_size_type nvals = 0;
read_binary(is, key);
read_binary(is, nvals);
if(nvals > 0) {
read_binary(is, target_id_buf);
read_binary(is, window_id_buf);

auto it = insert_into_slot(std::move(key), nullptr, 0, 0);
if(it == buckets_.end()) continue;

it->resize(alloc_, nvals);

for(auto v = it->values_, e = v+nvals; v < e; ++v) {
read_binary(is, *v);
for(size_t i = 0; i < nvals; ++i) {
it->values_[i] = {target_id_buf[i], window_id_buf[i]};
}
}
}
Expand All @@ -964,18 +974,32 @@ class hash_multimap
void serialize(std::ostream& os) const
{
using len_t = std::uint64_t;
using target_id = typename value_type::target_id_t;
using window_id = typename value_type::window_id_t;

write_binary(os, len_t(non_empty_bucket_count()));
write_binary(os, len_t(value_count()));

std::vector<target_id> target_id_buf;
std::vector<window_id> window_id_buf;

for(const auto& bucket : buckets_) {
if(!bucket.empty()) {
write_binary(os, bucket.key());
write_binary(os, bucket.size());

target_id_buf.clear();
target_id_buf.reserve(bucket.size());
window_id_buf.clear();
window_id_buf.reserve(bucket.size());

for(const auto& v : bucket) {
write_binary(os, v);
target_id_buf.emplace_back(v.tgt);
window_id_buf.emplace_back(v.win);
}

write_binary(os, target_id_buf);
write_binary(os, window_id_buf);
}
}
}
Expand Down
17 changes: 7 additions & 10 deletions src/io_serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ write_binary(std::ostream& os, const std::vector<T>& v)
{
std::uint64_t n = v.size();
os.write(reinterpret_cast<const char*>(&n), sizeof(n));
for(const auto& x : v) {
write_binary(os, x);
}
if(n > 0)
os.write(reinterpret_cast<const char*>(v.data()), n * sizeof(T));
}


Expand Down Expand Up @@ -116,13 +115,11 @@ inline void
read_binary(std::istream& is, std::vector<T>& v)
{

std::uint64_t l = 0;
is.read(reinterpret_cast<char*>(&l), sizeof(l));
v.clear();
v.resize(l);
for(auto& x : v) {
read_binary(is, x);
}
std::uint64_t n = 0;
is.read(reinterpret_cast<char*>(&n), sizeof(n));
v.resize(n);
if(n > 0)
is.read(reinterpret_cast<char*>(v.data()), n * sizeof(T));
}


Expand Down
11 changes: 3 additions & 8 deletions src/sketch_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ class sketch_database
//avoid padding bits
struct target_location
{
using target_id_t = target_id;
using window_id_t = window_id;

constexpr
target_location(target_id g = 0, window_id w = 0) noexcept :
tgt{g}, win{w}
Expand Down Expand Up @@ -871,10 +874,6 @@ class sketch_database

//target insertion parameters
read_binary(is, maxLocsPerFeature_);
//dummy for legacy db format compatibility
//could be re-used in the future
float dummy;
read_binary(is, dummy);

//taxon metadata
read_binary(is, taxa_);
Expand Down Expand Up @@ -944,10 +943,6 @@ class sketch_database

//target insertion parameters
write_binary(os, maxLocsPerFeature_);
//dummy for legacy db format compatibility
//could be re-used in the future
float dummy = 0.0f;
write_binary(os, dummy);

//taxon & target metadata
write_binary(os, taxa_);
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#define MC_VERSION 20180830

#define MC_DB_VERSION 20180227
#define MC_DB_VERSION 20180831

#define MC_VERSION_STRING "0.3.0"

Expand Down

0 comments on commit cecb9c2

Please sign in to comment.