1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:37:46 +00:00

AK: Let HashMap also take a ValueTraits

We were previously using Traits<V>, take that frrom the template
parameters instead.
This is needed by the Jakt runtime.
This commit is contained in:
Ali Mohammad Pur 2022-12-09 20:09:56 +03:30 committed by Ali Mohammad Pur
parent 58252a7684
commit 5809b4aafa
2 changed files with 16 additions and 16 deletions

View file

@ -80,11 +80,11 @@ class HashTable;
template<typename T, typename TraitsForT = Traits<T>> template<typename T, typename TraitsForT = Traits<T>>
using OrderedHashTable = HashTable<T, TraitsForT, true>; using OrderedHashTable = HashTable<T, TraitsForT, true>;
template<typename K, typename V, typename KeyTraits = Traits<K>, bool IsOrdered = false> template<typename K, typename V, typename KeyTraits = Traits<K>, typename ValueTraits = Traits<V>, bool IsOrdered = false>
class HashMap; class HashMap;
template<typename K, typename V, typename KeyTraits = Traits<K>> template<typename K, typename V, typename KeyTraits = Traits<K>, typename ValueTraits = Traits<V>>
using OrderedHashMap = HashMap<K, V, KeyTraits, true>; using OrderedHashMap = HashMap<K, V, KeyTraits, ValueTraits, true>;
template<typename T> template<typename T>
class Badge; class Badge;

View file

@ -13,7 +13,7 @@
namespace AK { namespace AK {
template<typename K, typename V, typename KeyTraits, bool IsOrdered> template<typename K, typename V, typename KeyTraits, typename ValueTraits, bool IsOrdered>
class HashMap { class HashMap {
private: private:
struct Entry { struct Entry {
@ -126,8 +126,8 @@ public:
ErrorOr<void> try_ensure_capacity(size_t capacity) { return m_table.try_ensure_capacity(capacity); } ErrorOr<void> try_ensure_capacity(size_t capacity) { return m_table.try_ensure_capacity(capacity); }
Optional<typename Traits<V>::ConstPeekType> get(K const& key) const Optional<typename ValueTraits::ConstPeekType> get(K const& key) const
requires(!IsPointer<typename Traits<V>::PeekType>) requires(!IsPointer<typename ValueTraits::PeekType>)
{ {
auto it = find(key); auto it = find(key);
if (it == end()) if (it == end())
@ -135,8 +135,8 @@ public:
return (*it).value; return (*it).value;
} }
Optional<typename Traits<V>::ConstPeekType> get(K const& key) const Optional<typename ValueTraits::ConstPeekType> get(K const& key) const
requires(IsPointer<typename Traits<V>::PeekType>) requires(IsPointer<typename ValueTraits::PeekType>)
{ {
auto it = find(key); auto it = find(key);
if (it == end()) if (it == end())
@ -144,8 +144,8 @@ public:
return (*it).value; return (*it).value;
} }
Optional<typename Traits<V>::PeekType> get(K const& key) Optional<typename ValueTraits::PeekType> get(K const& key)
requires(!IsConst<typename Traits<V>::PeekType>) requires(!IsConst<typename ValueTraits::PeekType>)
{ {
auto it = find(key); auto it = find(key);
if (it == end()) if (it == end())
@ -154,9 +154,9 @@ public:
} }
template<Concepts::HashCompatible<K> Key> template<Concepts::HashCompatible<K> Key>
requires(IsSame<KeyTraits, Traits<K>>) Optional<typename Traits<V>::PeekType> get(Key const& key) requires(IsSame<KeyTraits, Traits<K>>) Optional<typename ValueTraits::PeekType> get(Key const& key)
const const
requires(!IsPointer<typename Traits<V>::PeekType>) requires(!IsPointer<typename ValueTraits::PeekType>)
{ {
auto it = find(key); auto it = find(key);
if (it == end()) if (it == end())
@ -165,9 +165,9 @@ public:
} }
template<Concepts::HashCompatible<K> Key> template<Concepts::HashCompatible<K> Key>
requires(IsSame<KeyTraits, Traits<K>>) Optional<typename Traits<V>::ConstPeekType> get(Key const& key) requires(IsSame<KeyTraits, Traits<K>>) Optional<typename ValueTraits::ConstPeekType> get(Key const& key)
const const
requires(IsPointer<typename Traits<V>::PeekType>) requires(IsPointer<typename ValueTraits::PeekType>)
{ {
auto it = find(key); auto it = find(key);
if (it == end()) if (it == end())
@ -176,8 +176,8 @@ public:
} }
template<Concepts::HashCompatible<K> Key> template<Concepts::HashCompatible<K> Key>
requires(IsSame<KeyTraits, Traits<K>>) Optional<typename Traits<V>::PeekType> get(Key const& key) requires(IsSame<KeyTraits, Traits<K>>) Optional<typename ValueTraits::PeekType> get(Key const& key)
requires(!IsConst<typename Traits<V>::PeekType>) requires(!IsConst<typename ValueTraits::PeekType>)
{ {
auto it = find(key); auto it = find(key);
if (it == end()) if (it == end())