1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 19:57:45 +00:00

AK: Support using custom comparison operations for hash compatible keys

This commit is contained in:
Idan Horowitz 2022-01-29 20:01:35 +02:00
parent 4a99170cd2
commit 9b0d90a71d
3 changed files with 8 additions and 8 deletions

View file

@ -119,17 +119,16 @@ public:
return m_table.find(hash, predicate);
}
// FIXME: Use some sort of Traits to get the comparison operation
template<Concepts::HashCompatible<K> Key>
requires(IsSame<KeyTraits, Traits<K>>) [[nodiscard]] IteratorType find(Key const& value)
requires(IsSame<KeyTraits, Traits<K>>) [[nodiscard]] IteratorType find(Key const& key)
{
return m_table.find(Traits<Key>::hash(value), [&](auto& entry) { return value == entry.key; });
return m_table.find(Traits<Key>::hash(key), [&](auto& entry) { return Traits<K>::equals(key, entry.key); });
}
template<Concepts::HashCompatible<K> Key>
requires(IsSame<KeyTraits, Traits<K>>) [[nodiscard]] ConstIteratorType find(Key const& value) const
requires(IsSame<KeyTraits, Traits<K>>) [[nodiscard]] ConstIteratorType find(Key const& key) const
{
return m_table.find(Traits<Key>::hash(value), [&](auto& entry) { return value == entry.key; });
return m_table.find(Traits<Key>::hash(key), [&](auto& entry) { return Traits<K>::equals(key, entry.key); });
}
void ensure_capacity(size_t capacity) { m_table.ensure_capacity(capacity); }