From 492b1cf503355c17febda371bc4d5b45cd5ecef8 Mon Sep 17 00:00:00 2001 From: cat Date: Wed, 21 Jan 2026 09:33:36 +0200 Subject: [PATCH] Second iteration of DKM --- headers/Containers/DualkeyMap.hpp | 39 +++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/headers/Containers/DualkeyMap.hpp b/headers/Containers/DualkeyMap.hpp index 6d728f4..2d9421b 100644 --- a/headers/Containers/DualkeyMap.hpp +++ b/headers/Containers/DualkeyMap.hpp @@ -9,23 +9,52 @@ #ifndef GUARD_TOURMALINE_DUALKEYMAP_H #define GUARD_TOURMALINE_DUALKEYMAP_H #include +#include #include namespace Tourmaline::Containers { -template class DualkeyMap { +template +class DualkeyMap { + constexpr static uint64_t EmptyKey = -1; + DualkeyMap() { + ValueList.reserve(baseReservation); + HashList.reserve(baseReservation); + } + + ~DualkeyMap() { + // I'm sure there is a better way to do this + for (auto value : ValueList) { + delete value; + } + + for (auto hash : HashList) { + delete hash.Apointer; + delete hash.Bpointer; + } + } + + // No copying, No moving. Moving may be valid in the future. + // However as of now it is not a wise way to use this map. + DualkeyMap(const DualkeyMap &) = delete; + DualkeyMap(DualkeyMap &&) = delete; + DualkeyMap &operator=(const DualkeyMap &) = delete; + DualkeyMap &operator=(DualkeyMap &&) = delete; private: struct DualkeyHash { - DualkeyHash(std::size_t AHash, A *APointer, std::size_t BHash, B *BPointer) + DualkeyHash(std::size_t AHash, AKey *APointer, std::size_t BHash, + BKey *BPointer) : AKeyHash(AHash), APointer(APointer), BKeyHash(BHash), BPointer(BPointer) {} std::size_t AKeyHash = 0; std::size_t BKeyHash = 0; - A *APointer; - B *BPointer; + AKey *APointer; + BKey *BPointer; }; std::vector ValueList; - std::vector HashList{}; + std::vector HashList; }; } // namespace Tourmaline::Containers #endif