Skip to content

Commit

Permalink
extended pmr test, fixed another allocator issue in segmented_vector
Browse files Browse the repository at this point in the history
  • Loading branch information
martinus committed Jul 16, 2023
1 parent e3109cd commit 135b11e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.12)
project("unordered_dense"
VERSION 4.0.2
VERSION 4.0.3
DESCRIPTION "A fast & densely stored hashmap and hashset based on robin-hood backward shift deletion"
HOMEPAGE_URL "https://github.com/martinus/unordered_dense")

Expand Down
6 changes: 4 additions & 2 deletions include/ankerl/unordered_dense.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
///////////////////////// ankerl::unordered_dense::{map, set} /////////////////////////

// A fast & densely stored hashmap and hashset based on robin-hood backward shift deletion.
// Version 4.0.2
// Version 4.0.3
// https://github.com/martinus/unordered_dense
//
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
Expand Down Expand Up @@ -32,7 +32,7 @@
// see https://semver.org/spec/v2.0.0.html
#define ANKERL_UNORDERED_DENSE_VERSION_MAJOR 4 // NOLINT(cppcoreguidelines-macro-usage) incompatible API changes
#define ANKERL_UNORDERED_DENSE_VERSION_MINOR 0 // NOLINT(cppcoreguidelines-macro-usage) backwards compatible functionality
#define ANKERL_UNORDERED_DENSE_VERSION_PATCH 2 // NOLINT(cppcoreguidelines-macro-usage) backwards compatible bug fixes
#define ANKERL_UNORDERED_DENSE_VERSION_PATCH 3 // NOLINT(cppcoreguidelines-macro-usage) backwards compatible bug fixes

// API versioning with inline namespace, see https://www.foonathan.net/2018/11/inline-namespaces/

Expand Down Expand Up @@ -630,6 +630,8 @@ class segmented_vector {
m_blocks = std::move(other.m_blocks);
m_size = std::exchange(other.m_size, {});
} else {
// make sure to construct with other's allocator!
m_blocks = std::vector<pointer, vec_alloc>(vec_alloc(other.get_allocator()));
append_everything_from(std::move(other));
}
return *this;
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#

project('unordered_dense', 'cpp',
version: '4.0.2',
version: '4.0.3',
license: 'MIT',
default_options : [
'cpp_std=c++17',
Expand Down
2 changes: 1 addition & 1 deletion test/unit/namespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <doctest.h>

namespace versioned_namespace = ankerl::unordered_dense::v4_0_2;
namespace versioned_namespace = ankerl::unordered_dense::v4_0_3;

static_assert(std::is_same_v<versioned_namespace::map<int, int>, ankerl::unordered_dense::map<int, int>>);
static_assert(std::is_same_v<versioned_namespace::hash<int>, ankerl::unordered_dense::hash<int>>);
Expand Down
28 changes: 15 additions & 13 deletions test/unit/pmr_move_with_allocators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
// windows' vector has different allocation behavior, macos has linker errors
# if __linux__

using int_str_map = ankerl::unordered_dense::pmr::map<int, std::string>;
using int_str_map_segmented = ankerl::unordered_dense::pmr::segmented_map<int, std::string>;

namespace {

// creates a map and moves it out
template <typename Map>
auto return_hello_world(ANKERL_UNORDERED_DENSE_PMR::memory_resource* resource) {
auto return_hello_world(ANKERL_UNORDERED_DENSE_PMR::memory_resource* resource) -> Map {
Map map_default_resource(resource);
map_default_resource[0] = "Hello";
map_default_resource[1] = "World";
Expand All @@ -24,28 +21,33 @@ auto return_hello_world(ANKERL_UNORDERED_DENSE_PMR::memory_resource* resource) {

template <typename Map>
auto doTest() {
Map map_default_resource(ANKERL_UNORDERED_DENSE_PMR::new_delete_resource());

ANKERL_UNORDERED_DENSE_PMR::synchronized_pool_resource pool;

// segfaults if m_buckets is reused
{
map_default_resource = return_hello_world<Map>(&pool);
REQUIRE(map_default_resource.contains(0));
Map m(ANKERL_UNORDERED_DENSE_PMR::new_delete_resource());
m = return_hello_world<Map>(&pool);
REQUIRE(m.contains(0));
}

{
Map m(ANKERL_UNORDERED_DENSE_PMR::new_delete_resource());
m[0] = "foo";
m = return_hello_world<Map>(&pool);
REQUIRE(m[0] == "Hello");
}

{
Map map_default_resource_construct(return_hello_world<Map>(&pool), ANKERL_UNORDERED_DENSE_PMR::new_delete_resource());
REQUIRE(map_default_resource.contains(0));
Map m(return_hello_world<Map>(&pool), ANKERL_UNORDERED_DENSE_PMR::new_delete_resource());
REQUIRE(m.contains(0));
}
}

TEST_CASE("move_with_allocators") {
doTest<int_str_map>();
doTest<ankerl::unordered_dense::pmr::map<int, std::string>>();
}

TEST_CASE("move_with_allocators_segmented") {
doTest<int_str_map_segmented>();
doTest<ankerl::unordered_dense::pmr::segmented_map<int, std::string>>();
}

} // namespace
Expand Down

0 comments on commit 135b11e

Please sign in to comment.