From 39ed2fa9a585ed96927d62ae9bde068e3e94e786 Mon Sep 17 00:00:00 2001 From: Lukas Tenbrink Date: Sat, 14 Feb 2026 13:20:48 +0100 Subject: [PATCH] Add move semantics to `HashSet`. --- core/templates/hash_set.h | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/core/templates/hash_set.h b/core/templates/hash_set.h index 048ebc7b36..056650707b 100644 --- a/core/templates/hash_set.h +++ b/core/templates/hash_set.h @@ -421,6 +421,24 @@ public: _init_from(p_other); } + HashSet(HashSet &&p_other) { + _keys = p_other._keys; + _hash_idx_to_key_idx = p_other._hash_idx_to_key_idx; + _key_idx_to_hash_idx = p_other._key_idx_to_hash_idx; + _hashes = p_other._hashes; + + _capacity_idx = p_other._capacity_idx; + _size = p_other._size; + + p_other._keys = nullptr; + p_other._hash_idx_to_key_idx = nullptr; + p_other._hashes = nullptr; + p_other._key_idx_to_hash_idx = nullptr; + + p_other._capacity_idx = 0; + p_other._size = 0; + } + void operator=(const HashSet &p_other) { if (this == &p_other) { return; // Ignore self assignment. @@ -442,6 +460,20 @@ public: _init_from(p_other); } + void operator=(HashSet &&p_other) { + if (this == &p_other) { + return; // Ignore self assignment. + } + + SWAP(_keys, p_other._keys); + SWAP(_hash_idx_to_key_idx, p_other._hash_idx_to_key_idx); + SWAP(_key_idx_to_hash_idx, p_other._key_idx_to_hash_idx); + SWAP(_hashes, p_other._hashes); + + SWAP(_capacity_idx, p_other._capacity_idx); + SWAP(_size, p_other._size); + } + bool operator==(const HashSet &p_other) const { if (_size != p_other._size) { return false; @@ -465,7 +497,6 @@ public: HashSet() { _capacity_idx = MIN_CAPACITY_INDEX; } - HashSet(std::initializer_list p_init) { reserve(p_init.size()); for (const TKey &E : p_init) {