Skip to content

Commit

Permalink
A few more min&max fixes. Bump version, create a test that includes W…
Browse files Browse the repository at this point in the history
…indows.h
  • Loading branch information
martinus committed Feb 24, 2023
1 parent a3fea4a commit 10782bf
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 7 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 3.1.0
VERSION 3.1.1
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
8 changes: 4 additions & 4 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 3.1.0
// Version 3.1.1
// 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 3 // NOLINT(cppcoreguidelines-macro-usage) incompatible API changes
#define ANKERL_UNORDERED_DENSE_VERSION_MINOR 1 // NOLINT(cppcoreguidelines-macro-usage) backwards compatible functionality
#define ANKERL_UNORDERED_DENSE_VERSION_PATCH 0 // NOLINT(cppcoreguidelines-macro-usage) backwards compatible bug fixes
#define ANKERL_UNORDERED_DENSE_VERSION_PATCH 1 // NOLINT(cppcoreguidelines-macro-usage) backwards compatible bug fixes

// API versioning with inline namespace, see https://www.foonathan.net/2018/11/inline-namespaces/
#define ANKERL_UNORDERED_DENSE_VERSION_CONCAT1(major, minor, patch) v##major##_##minor##_##patch
Expand Down Expand Up @@ -1272,7 +1272,7 @@ class table : public std::conditional_t<is_map_v<T>, base_table_type_map<T>, bas
auto const last_to_end = std::distance(last, cend());

// remove elements from left to right which moves elements from the end back
auto const mid = idx_first + std::min(first_to_last, last_to_end);
auto const mid = idx_first + (std::min)(first_to_last, last_to_end);
auto idx = idx_first;
while (idx != mid) {
erase(begin() + idx);
Expand Down Expand Up @@ -1439,7 +1439,7 @@ class table : public std::conditional_t<is_map_v<T>, base_table_type_map<T>, bas
}

void rehash(size_t count) {
count = std::min(count, max_size());
count = (std::min)(count, max_size());
auto shifts = calc_shifts_for_size((std::max)(count, size()));
if (shifts != m_shifts) {
m_shifts = shifts;
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: '3.1.0',
version: '3.1.1',
license: 'MIT',
default_options : ['cpp_std=c++17', 'warning_level=3', 'werror=true'])

Expand Down
1 change: 1 addition & 0 deletions test/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ test_sources = [
'unit/unique_ptr.cpp',
'unit/unordered_set.cpp',
'unit/vectorofmaps.cpp',
'unit/windows_include.cpp',
]

# additional compile options
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::v3_1_0;
namespace versioned_namespace = ankerl::unordered_dense::v3_1_1;

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
118 changes: 118 additions & 0 deletions test/unit/windows_include.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#if defined(__has_include)
# if __has_include(<Windows.h>)
# include <Windows.h>
# pragma message("Windows.h included")
# endif
#endif

#include <ankerl/unordered_dense.h>
#include <app/counter.h>

#include <doctest.h>

#include <initializer_list>

TEST_CASE("unordered_dense_with_windows_h") {
auto counts = counter();
using map_t = ankerl::unordered_dense::map<counter::obj, counter::obj>;
auto map = map_t();

{
auto key = size_t(1);
auto it = map.try_emplace(counter::obj(key, counts), counter::obj(key, counts)).first;
REQUIRE(it != map.end());
REQUIRE(it->first.get() == key);
}
{
auto key = size_t(2);
map.emplace(std::piecewise_construct, std::forward_as_tuple(key, counts), std::forward_as_tuple(key + 77, counts));
}
{
auto key = size_t(3);
map[counter::obj(key, counts)] = counter::obj(key + 123, counts);
}
{
auto key = size_t(4);
map.insert(std::pair<counter::obj, counter::obj>(counter::obj(key, counts), counter::obj(key, counts)));
}
{
auto key = size_t(5);
map.insert_or_assign(counter::obj(key, counts), counter::obj(key + 1, counts));
}
{
auto key = size_t(6);
map.erase(counter::obj(key, counts));
}
{ map = map_t{}; }
{
auto m = map_t{};
m.swap(map);
}
{ map.clear(); }
{
auto s = size_t(7);
map.rehash(s);
}
{
auto s = size_t(8);
map.reserve(s);
}
{
auto key = size_t(9);
auto it = map.find(counter::obj(key, counts));
auto d = std::distance(map.begin(), it);
REQUIRE(0 <= d);
REQUIRE(d <= static_cast<std::ptrdiff_t>(map.size()));
}
{
if (!map.empty()) {
auto idx = static_cast<int>(map.size() / 2);
auto it = map.cbegin() + idx;
auto const& key = it->first;
auto found_it = map.find(key);
REQUIRE(it == found_it);
}
}
{
if (!map.empty()) {
auto it = map.begin() + static_cast<int>(map.size() / 2);
map.erase(it);
}
}
{
auto tmp = map_t();
std::swap(tmp, map);
}
{
map = std::initializer_list<std::pair<counter::obj, counter::obj>>{
{{1, counts}, {2, counts}},
{{3, counts}, {4, counts}},
{{5, counts}, {6, counts}},
};
REQUIRE(map.size() == 3);
}
{
auto first_idx = 0;
auto last_idx = 0;
if (!map.empty()) {
first_idx = static_cast<int>(map.size() / 2);
last_idx = static_cast<int>(map.size() / 2);
if (first_idx > last_idx) {
std::swap(first_idx, last_idx);
}
}
map.erase(map.cbegin() + first_idx, map.cbegin() + last_idx);
}
{
map.~map_t();
counts.check_all_done();
new (&map) map_t();
}
{
bool b = true;
std::erase_if(map, [&](map_t::value_type const& /*v*/) {
b = !b;
return b;
});
}
}

0 comments on commit 10782bf

Please sign in to comment.