From 6aaf0c61010af9c047c664168cb0cd609fec055b Mon Sep 17 00:00:00 2001 From: cat Date: Wed, 28 Jan 2026 13:32:09 +0200 Subject: [PATCH] Added ::Entry for returning references upon insertion Additionally fixed a minor mistake on hashable concept --- headers/Containers/DualkeyMap.hpp | 10 +++++++--- headers/Containers/Hashing.hpp | 3 +-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/headers/Containers/DualkeyMap.hpp b/headers/Containers/DualkeyMap.hpp index 0b18f13..5baf891 100644 --- a/headers/Containers/DualkeyMap.hpp +++ b/headers/Containers/DualkeyMap.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -30,6 +31,7 @@ public: std::pair, std::reference_wrapper>, Value &>; + using Entry = std::tuple; DualkeyMap() { hashList.reserve(baseReservation); } ~DualkeyMap() { @@ -41,7 +43,7 @@ public: } } - void insert(AKey firstKey, BKey secondKey, Value value) { + Entry insert(AKey firstKey, BKey secondKey, Value value) { std::size_t firstKeyHash = std::hash{}(firstKey); std::size_t secondKeyHash = std::hash{}(secondKey); DualkeyHash *hash = @@ -55,6 +57,8 @@ public: graveyard.pop(); hashList[tombstone] = hash; } + + return {hash->firstKey, hash->secondKey, hash->value}; } std::size_t remove(std::optional firstKey, @@ -192,8 +196,8 @@ private: struct DualkeyHash { DualkeyHash(std::size_t firstKeyHash, AKey &&firstKey, std::size_t secondKeyHash, BKey &&secondKey, Value &&value) - : firstKeyHash(firstKeyHash), firstKey(std::move(firstKey)), - secondKeyHash(secondKeyHash), secondKey(std::move(secondKey)), + : firstKeyHash(firstKeyHash), secondKeyHash(secondKeyHash), + firstKey(std::move(firstKey)), secondKey(std::move(secondKey)), value(std::move(value)) {} std::size_t firstKeyHash = 0; diff --git a/headers/Containers/Hashing.hpp b/headers/Containers/Hashing.hpp index 4f64711..c924451 100644 --- a/headers/Containers/Hashing.hpp +++ b/headers/Containers/Hashing.hpp @@ -14,8 +14,7 @@ namespace Tourmaline::Containers { template -concept Hashable = requires(T x) { - std::equality_comparable; +concept Hashable = std::equality_comparable && requires(T x) { { std::hash{}(x) } -> std::convertible_to; }; } // namespace Tourmaline::Containers