mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:57:34 +00:00
AK: Add HashMap::find() with customizable finder callback
This will allow clients to search the map without having to instantiate a key value.
This commit is contained in:
parent
cd8278e489
commit
bb32fd8bfa
1 changed files with 10 additions and 0 deletions
10
AK/HashMap.h
10
AK/HashMap.h
|
@ -56,6 +56,11 @@ public:
|
||||||
{
|
{
|
||||||
return m_table.find(KeyTraits::hash(key), [&](auto& entry) { return KeyTraits::equals(key, entry.key); });
|
return m_table.find(KeyTraits::hash(key), [&](auto& entry) { return KeyTraits::equals(key, entry.key); });
|
||||||
}
|
}
|
||||||
|
template<typename Finder>
|
||||||
|
IteratorType find(unsigned hash, Finder finder)
|
||||||
|
{
|
||||||
|
return m_table.find(hash, finder);
|
||||||
|
}
|
||||||
|
|
||||||
ConstIteratorType begin() const { return m_table.begin(); }
|
ConstIteratorType begin() const { return m_table.begin(); }
|
||||||
ConstIteratorType end() const { return m_table.end(); }
|
ConstIteratorType end() const { return m_table.end(); }
|
||||||
|
@ -63,6 +68,11 @@ public:
|
||||||
{
|
{
|
||||||
return m_table.find(KeyTraits::hash(key), [&](auto& entry) { return KeyTraits::equals(key, entry.key); });
|
return m_table.find(KeyTraits::hash(key), [&](auto& entry) { return KeyTraits::equals(key, entry.key); });
|
||||||
}
|
}
|
||||||
|
template<typename Finder>
|
||||||
|
ConstIteratorType find(unsigned hash, Finder finder) const
|
||||||
|
{
|
||||||
|
return m_table.find(hash, finder);
|
||||||
|
}
|
||||||
|
|
||||||
void ensure_capacity(int capacity) { m_table.ensure_capacity(capacity); }
|
void ensure_capacity(int capacity) { m_table.ensure_capacity(capacity); }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue