1#if !defined(phmap_dump_h_guard_)
2#define phmap_dump_h_guard_
29namespace type_traits_internal {
31#if defined(__GLIBCXX__) && __GLIBCXX__ < 20150801
32 template<
typename T>
struct IsTriviallyCopyable :
public std::integral_constant<bool, __has_trivial_copy(T)> {};
37template <
class T1,
class T2>
48template <
class Policy,
class Hash,
class Eq,
class Alloc>
49template<
typename OutputArchive>
50bool raw_hash_set<Policy, Hash, Eq, Alloc>::dump(OutputArchive& ar)
const {
52 "value_type should be trivially copyable");
54 if (!ar.dump(size_)) {
55 std::cerr <<
"Failed to dump size_" << std::endl;
61 if (!ar.dump(capacity_)) {
62 std::cerr <<
"Failed to dump capacity_" << std::endl;
65 if (!ar.dump(
reinterpret_cast<char*
>(ctrl_),
66 sizeof(ctrl_t) * (capacity_ + Group::kWidth + 1))) {
68 std::cerr <<
"Failed to dump ctrl_" << std::endl;
71 if (!ar.dump(
reinterpret_cast<char*
>(slots_),
72 sizeof(slot_type) * capacity_)) {
73 std::cerr <<
"Failed to dump slot_" << std::endl;
79template <
class Policy,
class Hash,
class Eq,
class Alloc>
80template<
typename InputArchive>
81bool raw_hash_set<Policy, Hash, Eq, Alloc>::load(InputArchive& ar) {
82 static_assert(type_traits_internal::IsTriviallyCopyable<value_type>::value,
83 "value_type should be trivially copyable");
84 raw_hash_set<Policy, Hash, Eq, Alloc>().swap(*
this);
85 if (!ar.load(&size_)) {
86 std::cerr <<
"Failed to load size_" << std::endl;
92 if (!ar.load(&capacity_)) {
93 std::cerr <<
"Failed to load capacity_" << std::endl;
99 if (!ar.load(
reinterpret_cast<char*
>(ctrl_),
100 sizeof(ctrl_t) * (capacity_ + Group::kWidth + 1))) {
101 std::cerr <<
"Failed to load ctrl" << std::endl;
104 if (!ar.load(
reinterpret_cast<char*
>(slots_),
105 sizeof(slot_type) * capacity_)) {
106 std::cerr <<
"Failed to load slot" << std::endl;
116 template <
class,
class,
class,
class>
class RefSet,
118 class Policy,
class Hash,
class Eq,
class Alloc>
119template<
typename OutputArchive>
120bool parallel_hash_set<N, RefSet, Mtx_, Policy, Hash, Eq, Alloc>::dump(OutputArchive& ar)
const {
121 static_assert(type_traits_internal::IsTriviallyCopyable<value_type>::value,
122 "value_type should be trivially copyable");
124 if (! ar.dump(subcnt())) {
125 std::cerr <<
"Failed to dump meta!" << std::endl;
128 for (
size_t i = 0; i < sets_.size(); ++i) {
129 auto& inner = sets_[i];
130 typename Lockable::UniqueLock m(
const_cast<Inner&
>(inner));
131 if (!inner.set_.dump(ar)) {
132 std::cerr <<
"Failed to dump submap " << i << std::endl;
140 template <
class,
class,
class,
class>
class RefSet,
142 class Policy,
class Hash,
class Eq,
class Alloc>
143template<
typename InputArchive>
144bool parallel_hash_set<N, RefSet, Mtx_, Policy, Hash, Eq, Alloc>::load(InputArchive& ar) {
145 static_assert(type_traits_internal::IsTriviallyCopyable<value_type>::value,
146 "value_type should be trivially copyable");
148 size_t submap_count = 0;
149 if (!ar.load(&submap_count)) {
150 std::cerr <<
"Failed to load submap count!" << std::endl;
154 if (submap_count != subcnt()) {
155 std::cerr <<
"submap count(" << submap_count <<
") != N(" << N <<
")" << std::endl;
159 for (
size_t i = 0; i < submap_count; ++i) {
160 auto& inner = sets_[i];
161 typename Lockable::UniqueLock m(
const_cast<Inner&
>(inner));
162 if (!inner.set_.load(ar)) {
163 std::cerr <<
"Failed to load submap " << i << std::endl;
183 ofs_.open(file_path, std::ios_base::binary);
186 bool dump(
const char *p,
size_t sz) {
192 typename std::enable_if<type_traits_internal::IsTriviallyCopyable<V>::value,
bool>::type
194 ofs_.write(
reinterpret_cast<const char *
>(&v),
sizeof(V));
206 ifs_.open(file_path, std::ios_base::binary);
209 bool load(
char* p,
size_t sz) {
215 typename std::enable_if<type_traits_internal::IsTriviallyCopyable<V>::value,
bool>::type
217 ifs_.read(
reinterpret_cast<char *
>(v),
sizeof(V));
Definition phmap_dump.h:180
Definition phmap_dump.h:34