From 671a001d3e078a42de1e83cbf2bd24a37c5dcc0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sat, 29 Aug 2026 21:43:51 +0000 Subject: [PATCH] tinystl: reset() keeps the bucket table; clear() still shrinks to 9. (#419) --- include/tinystl/unordered_map.h | 12 ++++++++++-- include/tinystl/unordered_set.h | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/include/tinystl/unordered_map.h b/include/tinystl/unordered_map.h index 8d2a7b3..6d3bd9d 100644 --- a/include/tinystl/unordered_map.h +++ b/include/tinystl/unordered_map.h @@ -57,6 +57,7 @@ namespace tinystl { const_iterator end() const; void clear(); + void reset(); bool empty() const; size_t size() const; @@ -180,6 +181,13 @@ namespace tinystl { template inline void unordered_map::clear() { + reset(); + m_buckets.last = m_buckets.first; + buffer_resize(&m_buckets, 9, 0); + } + + template + inline void unordered_map::reset() { if (m_buckets.first) { pointer it = *m_buckets.first; while (it) { @@ -189,10 +197,10 @@ namespace tinystl { it = next; } + + buffer_fill_urange(m_buckets.first, m_buckets.last, pointer(0)); } - m_buckets.last = m_buckets.first; - buffer_resize(&m_buckets, 9, 0); m_size = 0; } diff --git a/include/tinystl/unordered_set.h b/include/tinystl/unordered_set.h index d1eb579..8541f20 100644 --- a/include/tinystl/unordered_set.h +++ b/include/tinystl/unordered_set.h @@ -52,6 +52,7 @@ namespace tinystl { iterator end() const; void clear(); + void reset(); bool empty() const; size_t size() const; @@ -154,6 +155,13 @@ namespace tinystl { template inline void unordered_set::clear() { + reset(); + m_buckets.last = m_buckets.first; + buffer_resize(&m_buckets, 9, 0); + } + + template + inline void unordered_set::reset() { if (m_buckets.first) { pointer it = *m_buckets.first; while (it) { @@ -163,10 +171,10 @@ namespace tinystl { it = next; } + + buffer_fill_urange(m_buckets.first, m_buckets.last, pointer(0)); } - m_buckets.last = m_buckets.first; - buffer_resize(&m_buckets, 9, 0); m_size = 0; }