diff --git a/CMakeLists.txt b/CMakeLists.txt index 962fe1c..df94f4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -208,7 +208,7 @@ if (PHMAP_BUILD_EXAMPLES) # ------------------------------------------------------------- find_package(OpenMP) find_package(Boost 1.70.0) - if (OPENMP_FOUND AND Boost_FOUND AND "cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES) + if (OpenMP_FOUND AND Boost_FOUND AND "cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES) add_executable(ex_llil4map examples/llil4map.cc phmap.natvis) target_include_directories(ex_llil4map PRIVATE ${Boost_INCLUDE_DIRS}) target_compile_features(ex_llil4map PUBLIC cxx_std_20) @@ -219,11 +219,17 @@ if (PHMAP_BUILD_EXAMPLES) target_link_libraries(ex_llil4map PRIVATE OpenMP::OpenMP_CXX) target_compile_options(ex_llil4map PRIVATE "${OpenMP_CXX_FLAGS}") + file(COPY examples/llil_utils DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") + endif() + + if (Boost_FOUND) + add_executable(ex_custom_pointer examples/custom_pointer.cc phmap.natvis) + target_include_directories(ex_custom_pointer PRIVATE ${Boost_INCLUDE_DIRS}) + add_executable(ex_llil examples/llil.cc phmap.natvis) target_include_directories(ex_llil PRIVATE ${Boost_INCLUDE_DIRS}) target_compile_features(ex_llil PUBLIC cxx_std_20) - - file(COPY examples/llil_utils DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") + target_link_libraries(ex_llil Threads::Threads) endif() target_link_libraries(ex_knucleotide Threads::Threads) diff --git a/examples/custom_pointer.cc b/examples/custom_pointer.cc new file mode 100644 index 0000000..3a1537c --- /dev/null +++ b/examples/custom_pointer.cc @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include + +using mmap_file_t = boost::interprocess::managed_mapped_file; + +template +using bi_alloc_t = boost::interprocess::allocator; + +template +using scoped_alloc_t = std::scoped_allocator_adaptor; + +void simple_map() { + struct LatpLon { + int32_t latp; + int32_t lon; + }; + + using nodestore_pair_t = std::pair; + using map_t = phmap::flat_hash_map, std::equal_to, + bi_alloc_t>; + + auto mmap_file = + boost::interprocess::managed_mapped_file(boost::interprocess::open_or_create, "map_iv.dat", 1000000); + map_t* map = mmap_file.find_or_construct("node_store")(mmap_file.get_segment_manager()); + + for (unsigned int i = 0; i < 1000; ++i) { + LatpLon p = {10, 10}; + map->emplace(i, p); + } + + std::cout << map->at(10).latp << " " << map->at(10).lon << std::endl; +} + +void scoped_map() { + using way_t = std::vector>; + using waystore_pair_t = std::pair; + using map_t = phmap::flat_hash_map, std::equal_to, + std::scoped_allocator_adaptor>>; + + auto mmap_file = + boost::interprocess::managed_mapped_file(boost::interprocess::open_or_create, "map_iv.dat", 1000000); + map_t* map = mmap_file.find_or_construct("ways_store")(mmap_file.get_segment_manager()); + + for (unsigned int i = 0; i < 1000; ++i) { + std::vector init = {1, 2, 3, 4}; + map->emplace(std::piecewise_construct, std::forward_as_tuple(i), std::forward_as_tuple(init.begin(), init.end())); + } + + std::cout << map->at(10).size() << std::endl; + for (auto const& i : map->at(10)) + std::cout << i << " "; + std::cout << std::endl; +} + +int main() +{ + simple_map(); + scoped_map(); + return 0; +} \ No newline at end of file diff --git a/examples/llil.cc b/examples/llil.cc index a78c78b..2091cec 100644 --- a/examples/llil.cc +++ b/examples/llil.cc @@ -63,7 +63,6 @@ #include #include -#include #include #include diff --git a/parallel_hashmap/phmap.h b/parallel_hashmap/phmap.h index 2c18ab0..b2367ee 100644 --- a/parallel_hashmap/phmap.h +++ b/parallel_hashmap/phmap.h @@ -926,12 +926,7 @@ private: using IsDecomposable = IsDecomposable; public: - static_assert(std::is_same::value, - "Allocators with custom pointer types are not supported"); - static_assert(std::is_same::value, - "Allocators with custom pointer types are not supported"); - - class iterator + class iterator { friend class raw_hash_set; diff --git a/parallel_hashmap/phmap_base.h b/parallel_hashmap/phmap_base.h index 09d4854..0c79dc0 100644 --- a/parallel_hashmap/phmap_base.h +++ b/parallel_hashmap/phmap_base.h @@ -4189,7 +4189,7 @@ void* Allocate(Alloc* alloc, size_t n) { using A = typename phmap::allocator_traits::template rebind_alloc; using AT = typename phmap::allocator_traits::template rebind_traits; A mem_alloc(*alloc); - void* p = AT::allocate(mem_alloc, (n + sizeof(M) - 1) / sizeof(M)); + void* p = &*AT::allocate(mem_alloc, (n + sizeof(M) - 1) / sizeof(M)); // `&*` to support custom pointers such as boost offset_ptr. assert(reinterpret_cast(p) % Alignment == 0 && "allocator does not respect alignment"); return p;