[Glacier] Add HashMap move semantics.

This commit is contained in:
Drew Galbraith 2024-01-11 18:29:29 -08:00
parent d74918409c
commit be392252a4
1 changed files with 19 additions and 4 deletions

View File

@ -18,9 +18,8 @@ class HashMap {
HashMap() = default;
HashMap(const HashMap&) = delete;
HashMap& operator=(const HashMap&) = delete;
// TODO: Implement Move.
HashMap(HashMap&&) = delete;
HashMap& operator=(HashMap&&) = delete;
HashMap(HashMap&&);
HashMap& operator=(HashMap&&);
// Accessors.
uint64_t size() { return size_; }
@ -63,6 +62,21 @@ class HashMap {
void ResizeIfNecessary();
};
template <typename K, typename V, class H>
HashMap<K, V, H>::HashMap(HashMap&& other) {
data_ = glcr::Move(other.data_);
size_ = other.size_;
other.size_ = 0;
}
template <typename K, typename V, class H>
HashMap<K, V, H>& HashMap<K, V, H>::operator=(HashMap&& other) {
data_ = glcr::Move(other.data_);
size_ = other.size_;
other.size_ = 0;
return *this;
}
template <typename K, typename V, class H>
V& HashMap<K, V, H>::at(const K& key) {
uint64_t hc = H()(key);
@ -74,7 +88,8 @@ V& HashMap<K, V, H>::at(const K& key) {
}
}
// TODO: Add a failure mode here instead of constructing an object.
ll.PushFront({key, {}});
K k2 = key;
ll.PushFront({glcr::Move(k2), {}});
return ll.PeekFront().second();
}