1+ #include < boost/interprocess/managed_mapped_file.hpp>
2+ #include < scoped_allocator>
3+ #include < parallel_hashmap/phmap.h>
4+ #include < vector>
5+ #include < cstdint>
6+ #include < iostream>
7+
8+ using mmap_file_t = boost::interprocess::managed_mapped_file;
9+
10+ template <typename T>
11+ using bi_alloc_t = boost::interprocess::allocator<T, boost::interprocess::managed_mapped_file::segment_manager>;
12+
13+ template <typename T>
14+ using scoped_alloc_t = std::scoped_allocator_adaptor<T>;
15+
16+ void simple_map () {
17+ struct LatpLon {
18+ int32_t latp;
19+ int32_t lon;
20+ };
21+
22+ using nodestore_pair_t = std::pair<const uint64_t , LatpLon>;
23+ using map_t = phmap::flat_hash_map<const uint64_t , LatpLon, std::hash<uint64_t >, std::equal_to<uint64_t >,
24+ bi_alloc_t <nodestore_pair_t >>;
25+
26+ auto mmap_file =
27+ boost::interprocess::managed_mapped_file (boost::interprocess::open_or_create, " map_iv.dat" , 1000000 );
28+ map_t * map = mmap_file.find_or_construct <map_t >(" node_store" )(mmap_file.get_segment_manager ());
29+
30+ for (unsigned int i = 0 ; i < 1000 ; ++i) {
31+ LatpLon p = {10 , 10 };
32+ map->emplace (i, p);
33+ }
34+
35+ std::cout << map->at (10 ).latp << " " << map->at (10 ).lon << std::endl;
36+ }
37+
38+ void scoped_map () {
39+ using way_t = std::vector<uint64_t , bi_alloc_t <uint64_t >>;
40+ using waystore_pair_t = std::pair<const uint64_t , way_t >;
41+ using map_t = phmap::flat_hash_map<const uint64_t , way_t , std::hash<uint64_t >, std::equal_to<uint64_t >,
42+ std::scoped_allocator_adaptor<bi_alloc_t <waystore_pair_t >>>;
43+
44+ auto mmap_file =
45+ boost::interprocess::managed_mapped_file (boost::interprocess::open_or_create, " map_iv.dat" , 1000000 );
46+ map_t * map = mmap_file.find_or_construct <map_t >(" ways_store" )(mmap_file.get_segment_manager ());
47+
48+ for (unsigned int i = 0 ; i < 1000 ; ++i) {
49+ std::vector<uint64_t > init = {1 , 2 , 3 , 4 };
50+ map->emplace (std::piecewise_construct, std::forward_as_tuple (i), std::forward_as_tuple (init.begin (), init.end ()));
51+ }
52+
53+ std::cout << map->at (10 ).size () << std::endl;
54+ for (auto const & i : map->at (10 ))
55+ std::cout << i << " " ;
56+ std::cout << std::endl;
57+ }
58+
59+ int main ()
60+ {
61+ simple_map ();
62+ scoped_map ();
63+ return 0 ;
64+ }
0 commit comments