From 0b480f1eab31e89b64fd3cfe560d89aa72967739 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Sat, 4 Jan 2025 12:09:38 +0100 Subject: [PATCH] little polish of hashtable --- libsrc/core/hashtable.hpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/libsrc/core/hashtable.hpp b/libsrc/core/hashtable.hpp index 8e3ff813..64bf212e 100644 --- a/libsrc/core/hashtable.hpp +++ b/libsrc/core/hashtable.hpp @@ -841,6 +841,8 @@ namespace ngcore ar & hash & cont; ar & size & mask & used; } + + class EndIterator { }; class Iterator { @@ -858,24 +860,21 @@ namespace ngcore while (nr < tab.Size() && !tab.UsedPos(nr)) nr++; return *this; } - bool operator!= (const Iterator & it2) { return nr != it2.nr; } - auto operator* () const - { - T_HASH hash; - T val; - tab.GetData(nr, hash,val); - return std::make_pair(hash,val); - } + + bool operator!= (EndIterator & it2) { return nr != tab.Size(); } + + auto operator* () const { return tab.GetBoth(nr); } }; Iterator begin() const { return Iterator(*this, 0); } - Iterator end() const { return Iterator(*this, Size()); } + EndIterator end() const { return EndIterator(); } }; template ostream & operator<< (ostream & ost, const ClosedHashTable & tab) { + /* for (size_t i = 0; i < tab.Size(); i++) if (tab.UsedPos(i)) { @@ -884,6 +883,9 @@ namespace ngcore tab.GetData (i, key, val); ost << key << ": " << val << ", "; } + */ + for (auto [key,val] : tab) + ost << key << ": " << val << ", "; return ost; }