From 871629ffb362e6d002b0ed57a0aeb411b20a3a63 Mon Sep 17 00:00:00 2001 From: Martin Leitner-Ankerl Date: Mon, 11 Jul 2022 11:45:37 +0200 Subject: [PATCH] fix #8: erase() on empty map now works --- CMakeLists.txt | 2 +- include/ankerl/unordered_dense.h | 8 ++++++-- meson.build | 2 +- test/unit/erase.cpp | 6 ++++++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 236069f4..fd2eb37f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.12) project("unordered_dense" - VERSION 1.0.1 + VERSION 1.0.2 DESCRIPTION "A fast & densely stored hashmap and hashset based on robin-hood backward shift deletion" HOMEPAGE_URL "https://github.com/martinus/unordered_dense") diff --git a/include/ankerl/unordered_dense.h b/include/ankerl/unordered_dense.h index 52ec1765..7bc3f1cf 100644 --- a/include/ankerl/unordered_dense.h +++ b/include/ankerl/unordered_dense.h @@ -1,7 +1,7 @@ ///////////////////////// ankerl::unordered_dense::{map, set} ///////////////////////// // A fast & densely stored hashmap and hashset based on robin-hood backward shift deletion. -// Version 1.0.1 +// Version 1.0.2 // https://github.com/martinus/unordered_dense // // Licensed under the MIT License . @@ -32,7 +32,7 @@ // see https://semver.org/spec/v2.0.0.html #define ANKERL_UNORDERED_DENSE_VERSION_MAJOR 1 // incompatible API changes #define ANKERL_UNORDERED_DENSE_VERSION_MINOR 0 // add functionality in a backwards compatible manner -#define ANKERL_UNORDERED_DENSE_VERSION_PATCH 1 // backwards compatible bug fixes +#define ANKERL_UNORDERED_DENSE_VERSION_PATCH 2 // backwards compatible bug fixes #include #include @@ -527,6 +527,10 @@ class table { template auto do_erase_key(K&& key) -> size_t { + if (empty()) { + return 0; + } + auto [dist_and_fingerprint, bucket] = next_while_less(key); while (dist_and_fingerprint == bucket->dist_and_fingerprint && !m_equal(key, get_key(m_values[bucket->value_idx]))) { diff --git a/meson.build b/meson.build index 9d3ebf71..3bb55346 100644 --- a/meson.build +++ b/meson.build @@ -18,7 +18,7 @@ # project('unordered_dense', 'cpp', - version: '1.0.1', + version: '1.0.2', license: 'MIT', default_options : ['cpp_std=c++17', 'warning_level=3', 'werror=true']) diff --git a/test/unit/erase.cpp b/test/unit/erase.cpp index a93ce0f8..8be9806e 100644 --- a/test/unit/erase.cpp +++ b/test/unit/erase.cpp @@ -39,3 +39,9 @@ TEST_CASE("insert_erase_random") { us.erase(k); REQUIRE(is_eq(uds, us)); } + +TEST_CASE("erase") { + auto map = ankerl::unordered_dense::map(); + REQUIRE(0 == map.erase(123)); + REQUIRE(0 == map.count(0)); +}