cleanup example and test program. bracket load/dump calls so that file is closed.

This commit is contained in:
greg
2019-08-25 10:22:44 -04:00
parent daaed8b1aa
commit 2ff7c0fce7
2 changed files with 59 additions and 81 deletions
+24 -29
View File
@@ -1,50 +1,45 @@
#include <iostream>
#include <string>
#include <parallel_hashmap/phmap_dump.h>
using phmap::flat_hash_map;
using phmap::parallel_flat_hash_map;
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;
phmap::flat_hash_map<uint64_t, uint32_t> mp1 = { {100, 99}, {300, 299} };
// Iterate and print keys and values
for (const auto& n : mp1)
std::cout << n.first << "'s value is: " << n.second << "\n";
mp1.dump(ar_out);
flat_hash_map<uint64_t, uint32_t> mp2;
phmap::BinaryInputArchive ar_in("./dump.data");
mp2.load(ar_in);
// Iterate and print keys and values g|++
{
phmap::BinaryOutputArchive ar_out("./dump.data");
mp1.dump(ar_out);
}
phmap::flat_hash_map<uint64_t, uint32_t> mp2;
{
phmap::BinaryInputArchive ar_in("./dump.data");
mp2.load(ar_in);
}
for (const auto& n : mp2)
std::cout << n.first << "'s value is: " << n.second << "\n";
}
void dump_load_parallel_flat_hash_map() {
parallel_flat_hash_map<uint64_t, uint32_t> mp1;
phmap::BinaryOutputArchive ar_out("./dump.data");
phmap::parallel_flat_hash_map<uint64_t, uint32_t> mp1 = {
{100, 99}, {300, 299}, {101, 992} };
// Add a new entry
mp1[100] = 99;
mp1[300] = 299;
mp1[101] = 992;
mp1[1300] = 2991;
mp1[1130] = 299;
mp1[2130] = 1299;
// Iterate and print
for (const auto& n : mp1)
std::cout << "key: " << n.first << ", value: " << n.second << "\n";
mp1.dump(ar_out);
parallel_flat_hash_map<uint64_t, uint32_t> mp2;
phmap::BinaryInputArchive ar_in("./dump.data");
{
phmap::BinaryOutputArchive ar_out("./dump.data");
mp1.dump(ar_out);
}
phmap::parallel_flat_hash_map<uint64_t, uint32_t> mp2;
{
phmap::BinaryInputArchive ar_in("./dump.data");
mp2.load(ar_in);
}
mp2.load(ar_in);
for (const auto& n : mp2)
std::cout << "key: " << n.first << ", value: " << n.second << "\n";
}