mirror of
https://github.com/greg7mdp/parallel-hashmap.git
synced 2026-08-29 16:40:39 +08:00
Fix issue #44 - example to dump TriviallyCopyable types doesn't work any
more
This commit is contained in:
Regular → Executable
+6
-6
@@ -18,11 +18,11 @@ public:
|
|||||||
{
|
{
|
||||||
phmap::BinaryOutputArchive ar_out (filename.c_str());
|
phmap::BinaryOutputArchive ar_out (filename.c_str());
|
||||||
|
|
||||||
ar_out.dump(this->size());
|
ar_out.saveBinary(this->size());
|
||||||
for (auto& [k, v] : *this)
|
for (auto& [k, v] : *this)
|
||||||
{
|
{
|
||||||
ar_out.dump(k);
|
ar_out.saveBinary(k);
|
||||||
v.dump(ar_out);
|
ar_out.saveBinary(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ public:
|
|||||||
phmap::BinaryInputArchive ar_in(filename.c_str());
|
phmap::BinaryInputArchive ar_in(filename.c_str());
|
||||||
|
|
||||||
size_t size;
|
size_t size;
|
||||||
ar_in.load(&size);
|
ar_in.loadBinary(&size);
|
||||||
this->reserve(size);
|
this->reserve(size);
|
||||||
|
|
||||||
while (size--)
|
while (size--)
|
||||||
@@ -39,8 +39,8 @@ public:
|
|||||||
K k;
|
K k;
|
||||||
Set v;
|
Set v;
|
||||||
|
|
||||||
ar_in.load(&k);
|
ar_in.loadBinary(&k);
|
||||||
v.load(ar_in);
|
ar_in.loadBinary(&v);
|
||||||
|
|
||||||
this->insert_or_assign(std::move(k), std::move(v));
|
this->insert_or_assign(std::move(k), std::move(v));
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+26
@@ -158,6 +158,19 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename V>
|
||||||
|
typename std::enable_if<type_traits_internal::IsTriviallyCopyable<V>::value, bool>::type
|
||||||
|
saveBinary(const V& v) {
|
||||||
|
ofs_.write(reinterpret_cast<const char *>(&v), sizeof(V));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Map>
|
||||||
|
auto saveBinary(const Map& v) -> decltype(v.phmap_dump(*this), bool())
|
||||||
|
{
|
||||||
|
return v.phmap_dump(*this);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::ofstream ofs_;
|
std::ofstream ofs_;
|
||||||
};
|
};
|
||||||
@@ -174,6 +187,19 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename V>
|
||||||
|
typename std::enable_if<type_traits_internal::IsTriviallyCopyable<V>::value, bool>::type
|
||||||
|
loadBinary(V* v) {
|
||||||
|
ifs_.read(reinterpret_cast<char *>(v), sizeof(V));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Map>
|
||||||
|
auto loadBinary(Map* v) -> decltype(v->phmap_load(*this), bool())
|
||||||
|
{
|
||||||
|
return v->phmap_load(*this);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::ifstream ifs_;
|
std::ifstream ifs_;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user