mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-29 14:14:45 +03: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:
parent
58252a7684
commit
5809b4aafa
Notes:
sideshowbarker
2024-07-17 07:38:17 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/5809b4aafa Pull-request: https://github.com/SerenityOS/serenity/pull/16396 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/awesomekling ✅
@ -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;
|
||||
|
26
AK/HashMap.h
26
AK/HashMap.h
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user