use single file to store data for parallel hash

This commit is contained in:
sunkaicheng
2019-08-21 09:01:56 +08:00
parent e3c55f9830
commit 0866192922
4 changed files with 39 additions and 83 deletions
+19 -15
View File
@@ -3199,40 +3199,44 @@ public:
a.swap(b);
}
template<typename OutputArchiveWrapper, typename V = value_type>
template<typename OutputArchive, typename V = value_type>
typename std::enable_if<type_traits_internal::IsDumpableType<V>::value, bool>::type
dump(OutputArchiveWrapper& w) {
dump(OutputArchive& ar) {
typename OutputArchive::Guard guard(&ar);
if (! ar.dump(subcnt())) {
std::cerr << "Failed to dump meta!" << std::endl;
return false;
}
for (size_t i = 0; i < sets_.size(); ++i) {
auto& inner = sets_[i];
auto ar = w.create_archive(i);
typename Lockable::UniqueLock m(const_cast<Inner&>(inner));
if (!inner.set_.dump(*ar)) {
if (!inner.set_.dump(ar)) {
std::cerr << "Failed to dump submap " << i << std::endl;
return false;
}
}
if (! w.dump_meta(subcnt())) {
std::cerr << "Failed to dump meta!" << std::endl;
return false;
}
return true;
}
template<typename InputArchiveWrapper, typename V = value_type>
template<typename InputArchive, typename V = value_type>
typename std::enable_if<type_traits_internal::IsDumpableType<V>::value, bool>::type
load(InputArchiveWrapper& w) {
size_t submap_count = w.load_meta();
load(InputArchive& ar) {
typename InputArchive::Guard guard(&ar);
size_t submap_count = 0;
if (!ar.load(&submap_count)) {
std::cerr << "Failed to load submap count!" << std::endl;
return false;
}
if (submap_count != subcnt()) {
std::cerr << "submap count(" << submap_count << ") != N(" << N << ")" << std::endl;
return false;
}
for (size_t i = 0; i < sets_.size(); ++i) {
auto ar = w.create_archive(i);
for (size_t i = 0; i < submap_count; ++i) {
auto& inner = sets_[i];
if (!inner.set_.load(*ar)) {
typename Lockable::UniqueLock m(const_cast<Inner&>(inner));
if (!inner.set_.load(ar)) {
std::cerr << "Failed to load submap " << i << std::endl;
return false;
}