diff --git a/parallel_hashmap/phmap_dump.h b/parallel_hashmap/phmap_dump.h index aebf523..2eff9af 100644 --- a/parallel_hashmap/phmap_dump.h +++ b/parallel_hashmap/phmap_dump.h @@ -44,6 +44,8 @@ namespace priv { #if !defined(PHMAP_NON_DETERMINISTIC) && !defined(PHMAP_DISABLE_DUMP) +static constexpr size_t s_version_base = std::numeric_limits::max() - 10; +static constexpr size_t s_version = s_version_base; // ------------------------------------------------------------------------ // dump/load for raw_hash_set // ------------------------------------------------------------------------ @@ -53,6 +55,7 @@ bool raw_hash_set::phmap_dump(OutputArchive& ar) const static_assert(type_traits_internal::IsTriviallyCopyable::value, "value_type should be trivially copyable"); + ar.saveBinary(&s_version, sizeof(size_t)); ar.saveBinary(&size_, sizeof(size_t)); ar.saveBinary(&capacity_, sizeof(size_t)); if (size_ == 0) @@ -69,7 +72,15 @@ bool raw_hash_set::phmap_load(InputArchive& ar) { static_assert(type_traits_internal::IsTriviallyCopyable::value, "value_type should be trivially copyable"); raw_hash_set().swap(*this); // clear any existing content - ar.loadBinary(&size_, sizeof(size_t)); + + size_t version = 0; + ar.loadBinary(&version, sizeof(size_t)); + if (version < s_version_base) { + // we didn't store the version, version actually contains the size + size_ = version; + } else { + ar.loadBinary(&size_, sizeof(size_t)); + } ar.loadBinary(&capacity_, sizeof(size_t)); if (capacity_) { @@ -80,7 +91,9 @@ bool raw_hash_set::phmap_load(InputArchive& ar) { return true; ar.loadBinary(ctrl_, sizeof(ctrl_t) * (capacity_ + Group::kWidth + 1)); ar.loadBinary(slots_, sizeof(slot_type) * capacity_); - ar.loadBinary(&growth_left(), sizeof(size_t)); + if (version == s_version_base) { + ar.loadBinary(&growth_left(), sizeof(size_t)); + } return true; }