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
Notes: sideshowbarker 2024-07-17 07:38:17 +09:00
2 changed files with 16 additions and 16 deletions

View file

@ -80,11 +80,11 @@ class HashTable;
template<typename T, typename TraitsForT = Traits<T>>
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;
template<typename K, typename V, typename KeyTraits = Traits<K>>
using OrderedHashMap = HashMap<K, V, KeyTraits, true>;
template<typename K, typename V, typename KeyTraits = Traits<K>, typename ValueTraits = Traits<V>>
using OrderedHashMap = HashMap<K, V, KeyTraits, ValueTraits, true>;
template<typename T>
class Badge;

View file

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