From 43ab77729369797bec3b153bff08659db2a561d7 Mon Sep 17 00:00:00 2001 From: Julian LALU Date: Thu, 23 Jan 2025 14:44:13 +0100 Subject: [PATCH] Improve hashmap and hashset --- interface/core/containers/hashmap.h | 14 +++++------ interface/core/containers/hashset.h | 38 +++++++++-------------------- 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/interface/core/containers/hashmap.h b/interface/core/containers/hashmap.h index ee0888f..a7b6482 100644 --- a/interface/core/containers/hashmap.h +++ b/interface/core/containers/hashmap.h @@ -12,17 +12,15 @@ namespace hud using key_type = key_t; using value_type = value_t; - template - requires(hud::is_constructible_v) - constexpr explicit slot(params_t &&...params) noexcept - : element_(hud::forward(params)..., value_type {}) + constexpr explicit slot(const key_type &key, const value_type &value) noexcept + : element_(key, value) { } - template - requires(hud::is_constructible_v, params_t...>) - constexpr explicit slot(params_t &&...params) noexcept - : element_(hud::forward(params)...) + template + requires(hud::is_constructible_v, u_key_t, u_value_t>) + constexpr explicit slot(u_key_t &&key, u_value_t &&value) noexcept + : element_(hud::forward(key), hud::forward(value)) { } diff --git a/interface/core/containers/hashset.h b/interface/core/containers/hashset.h index 464085c..9b00636 100644 --- a/interface/core/containers/hashset.h +++ b/interface/core/containers/hashset.h @@ -22,10 +22,15 @@ namespace hud { using key_type = value_t; - template - requires(hud::is_constructible_v) - constexpr explicit slot(params_t &&...params) noexcept - : element_(hud::forward(params)...) + constexpr explicit slot(const key_type &key) noexcept + : element_(key) + { + } + + template + requires(hud::is_constructible_v) + constexpr explicit slot(u_key_t &&key) noexcept + : element_(hud::forward(key)) { } @@ -644,26 +649,6 @@ namespace hud } } - /** - * Insert a key in the hashset. - * @param key The key associated with the `value` - * @param args List of arguments pass to `value_type` constructor after the `key` itself - * @return Reference to the `value` - */ - // template - // // requires(hud::is_constructible_v) - // constexpr slot_type &add_to_ref(slot_type::key_type &&key, args_t &&...args) noexcept - - // { - // hud::pair res = find_or_insert_no_construct(key); - // slot_type *slot_ptr = slot_ptr_ + res.first; - // if (res.second) - // { - // hud::memory::construct_at(slot_ptr, hud::move(key), hud::forward(args)...); - // } - // return &slot_ptr; - // } - /** * Insert a key in the hashset. * @param key The key associated with the `value` @@ -671,8 +656,7 @@ namespace hud * @return Iterator to the `value` */ template - - // requires(hud::is_constructible_v) + requires(hud::is_constructible_v) constexpr iterator add(key_type &&key, args_t &&...args) noexcept { hud::pair res = find_or_insert_no_construct(key); @@ -691,7 +675,7 @@ namespace hud * @return Iterator to the `value` */ template - requires(hud::is_constructible_v) + requires(hud::is_constructible_v) constexpr iterator add(const key_type &key, args_t &&...args) noexcept { hud::pair res = find_or_insert_no_construct(key);