-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for custom container instead of only std::vector.
Adds a test that makes use of boost::interprocess. This also uses fancy pointers, so there are some updates needed to bucket handling.
- Loading branch information
Showing
7 changed files
with
183 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ jobs: | |
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- run: sudo apt-get install -yq libboost-dev | ||
- uses: hendrikmuhs/[email protected] | ||
- uses: actions/setup-python@v4 | ||
with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <ankerl/unordered_dense.h> | ||
|
||
#include <doctest.h> | ||
|
||
#include <deque> | ||
|
||
static_assert( | ||
ankerl::unordered_dense::detail::is_detected_v<ankerl::unordered_dense::detail::detect_iterator, std::deque<int>>); | ||
|
||
static_assert( | ||
!ankerl::unordered_dense::detail::is_detected_v<ankerl::unordered_dense::detail::detect_iterator, std::allocator<int>>); | ||
|
||
TEST_CASE("custom_container") { | ||
using Map = ankerl::unordered_dense:: | ||
map<int, std::string, ankerl::unordered_dense::hash<int>, std::equal_to<int>, std::deque<std::pair<int, std::string>>>; | ||
|
||
auto map = Map(); | ||
|
||
for (int i = 0; i < 10; ++i) { | ||
map[i] = std::to_string(i); | ||
} | ||
|
||
REQUIRE(std::is_same_v<std::deque<std::pair<int, std::string>>, typename Map::value_container_type>); | ||
std::deque<std::pair<int, std::string>> container = std::move(map).extract(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#if ANKERL_UNORDERED_DENSE_HAS_BOOST | ||
|
||
# include <ankerl/unordered_dense.h> | ||
|
||
# include <boost/container/vector.hpp> | ||
# include <boost/interprocess/allocators/allocator.hpp> | ||
# include <boost/interprocess/allocators/node_allocator.hpp> | ||
# include <boost/interprocess/containers/vector.hpp> | ||
# include <boost/interprocess/managed_shared_memory.hpp> | ||
# include <doctest.h> | ||
|
||
# include <deque> | ||
|
||
// See https://www.boost.org/doc/libs/1_80_0/doc/html/interprocess/allocators_containers.html | ||
TEST_CASE("boost_container_vector") { | ||
// Remove shared memory on construction and destruction | ||
struct ShmRemove { | ||
ShmRemove() { | ||
boost::interprocess::shared_memory_object::remove("MySharedMemory"); | ||
} | ||
~ShmRemove() { | ||
boost::interprocess::shared_memory_object::remove("MySharedMemory"); | ||
} | ||
} remover; | ||
|
||
// Create shared memory | ||
auto segment = boost::interprocess::managed_shared_memory(boost::interprocess::create_only, "MySharedMemory", 65536); | ||
|
||
// Alias an STL-like allocator of ints that allocates ints from the segment | ||
using ShmemAllocator = boost::interprocess::allocator<std::pair<int, std::string>, | ||
boost::interprocess::managed_shared_memory::segment_manager>; | ||
using ShmemVector = boost::interprocess::vector<std::pair<int, std::string>, ShmemAllocator>; | ||
|
||
using Map = | ||
ankerl::unordered_dense::map<int, std::string, ankerl::unordered_dense::hash<int>, std::equal_to<int>, ShmemVector>; | ||
|
||
auto map = Map{ShmemVector{ShmemAllocator{segment.get_segment_manager()}}}; | ||
|
||
for (int i = 0; i < 100; ++i) { | ||
map.try_emplace(i, std::to_string(i)); | ||
} | ||
|
||
REQUIRE(map.size() == 100); | ||
for (int i = 0; i < 100; ++i) { | ||
auto it = map.find(i); | ||
REQUIRE(it != map.end()); | ||
REQUIRE(it->first == i); | ||
REQUIRE(it->second == std::to_string(i)); | ||
} | ||
|
||
map.erase(123); | ||
REQUIRE(map.size() == 100); | ||
map.erase(29); | ||
REQUIRE(map.size() == 99); | ||
|
||
map.emplace(std::pair<int, std::string>(9999, "hello")); | ||
REQUIRE(map.size() == 100); | ||
} | ||
#endif |