[ox] Add HashMap<String, T> to serializaton handlers
This commit is contained in:
26
deps/ox/src/ox/std/hashmap.hpp
vendored
26
deps/ox/src/ox/std/hashmap.hpp
vendored
@@ -16,6 +16,9 @@ namespace ox {
|
||||
template<typename K, typename T>
|
||||
class HashMap {
|
||||
|
||||
using key_t = K;
|
||||
using value_t = T;
|
||||
|
||||
private:
|
||||
struct Pair {
|
||||
K key = {};
|
||||
@@ -31,6 +34,8 @@ class HashMap {
|
||||
|
||||
~HashMap();
|
||||
|
||||
bool operator==(const HashMap &other) const;
|
||||
|
||||
HashMap &operator=(HashMap &other);
|
||||
|
||||
/**
|
||||
@@ -47,6 +52,8 @@ class HashMap {
|
||||
|
||||
std::size_t size() const noexcept;
|
||||
|
||||
const Vector<K> &keys() const noexcept;
|
||||
|
||||
private:
|
||||
void expand();
|
||||
|
||||
@@ -78,6 +85,20 @@ HashMap<K, T>::~HashMap() {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
bool HashMap<K, T>::operator==(const HashMap &other) const {
|
||||
if (m_keys != other.m_keys) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < m_keys.size(); i++) {
|
||||
auto &k = m_keys[i];
|
||||
if (at(k) != other.at(k)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
HashMap<K, T> &HashMap<K, T>::operator=(HashMap<K, T> &other) {
|
||||
this->~HashMap<K, T>();
|
||||
@@ -115,6 +136,11 @@ std::size_t HashMap<K, T>::size() const noexcept {
|
||||
return m_keys.size();
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
const Vector<K> &HashMap<K, T>::keys() const noexcept {
|
||||
return m_keys;
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
void HashMap<K, T>::expand() {
|
||||
Vector<Pair*> r;
|
||||
|
Reference in New Issue
Block a user