refine code

This commit is contained in:
sunkaicheng
2019-08-16 21:24:02 +08:00
parent 5cd20dc4a6
commit dd9af7f8a5
4 changed files with 310 additions and 221 deletions
+32 -21
View File
@@ -8,7 +8,7 @@ using phmap::parallel_flat_hash_map;
void dump_load_string_string() {
flat_hash_map<std::string, std::string> mp1;
phmap::BinaryOutputArchive ar_out("./dump.data");
// Add a new entry
mp1["key-1"] = "value-1";
mp1["key-2"] = "value-2";
@@ -17,10 +17,12 @@ void dump_load_string_string() {
for (const auto& n : mp1)
std::cout << n.first << "'s value is: " << n.second << "\n";
mp1.dump("./dump.data");
mp1.dump(ar_out);
flat_hash_map<std::string, std::string> mp2;
mp2.load("./dump.data");
phmap::BinaryInputArchive ar_in("./dump.data");
mp2.load(ar_in);
// Iterate and print keys and values g|++
for (const auto& n : mp2)
std::cout << n.first << "'s value is: " << n.second << "\n";
@@ -30,7 +32,7 @@ void dump_load_string_string() {
void dump_load_uint64_uint32() {
flat_hash_map<uint64_t, uint32_t> mp1;
phmap::BinaryOutputArchive ar_out("./dump.data");
// Add a new entry
mp1[100] = 99;
mp1[300] = 299;
@@ -39,10 +41,10 @@ void dump_load_uint64_uint32() {
for (const auto& n : mp1)
std::cout << n.first << "'s value is: " << n.second << "\n";
mp1.dump("./dump.data");
mp1.dump(ar_out);
flat_hash_map<uint64_t, uint32_t> mp2;
mp2.load("./dump.data");
phmap::BinaryInputArchive ar_in("./dump.data");
mp2.load(ar_in);
// Iterate and print keys and values g|++
for (const auto& n : mp2)
std::cout << n.first << "'s value is: " << n.second << "\n";
@@ -52,7 +54,7 @@ void dump_load_uint64_uint32() {
void dump_load_string_uint32() {
flat_hash_map<std::string, uint32_t> mp1;
phmap::BinaryOutputArchive ar_out("./dump.data");
// Add a new entry
mp1["key-1"] = 99;
mp1["key-2"] = 299;
@@ -61,10 +63,11 @@ void dump_load_string_uint32() {
for (const auto& n : mp1)
std::cout << n.first << "'s value is: " << n.second << "\n";
mp1.dump("./dump.data");
mp1.dump(ar_out);
flat_hash_map<std::string, uint32_t> mp2;
phmap::BinaryInputArchive ar_in("./dump.data");
mp2.load("./dump.data");
mp2.load(ar_in);
// Iterate and print keys and values g|++
for (const auto& n : mp2)
std::cout << n.first << "'s value is: " << n.second << "\n";
@@ -74,6 +77,7 @@ void dump_load_string_uint32() {
void dump_load_uint32_string() {
flat_hash_map<uint32_t, std::string> mp1;
phmap::BinaryOutputArchive ar_out("./dump.data");
// Add a new entry
mp1[100] = "hello";
@@ -83,10 +87,11 @@ void dump_load_uint32_string() {
for (const auto& n : mp1)
std::cout << n.first << "'s value is: " << n.second << "\n";
mp1.dump("./dump.data");
mp1.dump(ar_out);
flat_hash_map<uint32_t, std::string> mp2;
phmap::BinaryInputArchive ar_in("./dump.data");
mp2.load("./dump.data");
mp2.load(ar_in);
// Iterate and print keys and values g|++
for (const auto& n : mp2)
std::cout << n.first << "'s value is: " << n.second << "\n";
@@ -96,7 +101,8 @@ void dump_load_uint32_string() {
void dump_load_string() {
flat_hash_set<std::string> st1;
phmap::BinaryOutputArchive ar_out("./dump.data");
// Add a new entry
st1.insert("hello");
st1.insert("world");
@@ -105,10 +111,11 @@ void dump_load_string() {
for (const auto& n : st1)
std::cout << "value: " << n << "\n";
st1.dump("./dump.data");
st1.dump(ar_out);
flat_hash_set<std::string> st2;
phmap::BinaryInputArchive ar_in("./dump.data");
st2.load("./dump.data");
st2.load(ar_in);
// Iterate and print keys and values g|++
for (const auto& n : st2)
std::cout << "value: " << n << "\n";
@@ -118,7 +125,8 @@ void dump_load_string() {
void dump_load_uint64() {
flat_hash_set<uint64_t> st1;
phmap::BinaryOutputArchive ar_out("./dump.data");
// Add a new entry
st1.insert(878);
st1.insert(1424);
@@ -127,10 +135,11 @@ void dump_load_uint64() {
for (const auto& n : st1)
std::cout << "value: " << n << "\n";
st1.dump("./dump.data");
st1.dump(ar_out);
flat_hash_set<uint64_t> st2;
phmap::BinaryInputArchive ar_in("./dump.data");
st2.load("./dump.data");
st2.load(ar_in);
// Iterate and print keys and values g|++
for (const auto& n : st2)
std::cout << "value: " << n << "\n";
@@ -140,7 +149,8 @@ void dump_load_uint64() {
void dump_load_parallel_flat_hash_map() {
parallel_flat_hash_map<uint64_t, uint32_t> mp1;
phmap::OutputArchiveWrapper<phmap::BinaryOutputArchive> w_out("./");
// Add a new entry
mp1[100] = 99;
mp1[300] = 299;
@@ -152,10 +162,11 @@ void dump_load_parallel_flat_hash_map() {
for (const auto& n : mp1)
std::cout << "key: " << n.first << ", value: " << n.second << "\n";
mp1.dump("./dump");
mp1.dump(w_out);
parallel_flat_hash_map<uint64_t, uint32_t> mp2;
phmap::InputArchiveWrapper<phmap::BinaryInputArchive> w_in("./");
mp2.load("./dump");
mp2.load(w_in);
for (const auto& n : mp2)
std::cout << "key: " << n.first << ", value: " << n.second << "\n";
}