mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-13 01:59:14 +03:00
AK: Simplify HashMap a bit.
This commit is contained in:
parent
65e470c90a
commit
ebe108efa6
Notes:
sideshowbarker
2024-07-19 13:28:15 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/ebe108efa65
47
AK/HashMap.h
47
AK/HashMap.h
@ -14,7 +14,7 @@ private:
|
||||
K key;
|
||||
V value;
|
||||
|
||||
bool operator==(const Entry& other)
|
||||
bool operator==(const Entry& other) const
|
||||
{
|
||||
return key == other.key;
|
||||
}
|
||||
@ -39,9 +39,9 @@ public:
|
||||
int capacity() const { return m_table.capacity(); }
|
||||
void clear() { m_table.clear(); }
|
||||
|
||||
void set(const K&, const V&);
|
||||
void set(const K&, V&&);
|
||||
void remove(const K&);
|
||||
void set(const K& key, const V& value) { m_table.set({ key, value }); }
|
||||
void set(const K& key, V&& value) { m_table.set({ key, move(value) }); }
|
||||
void remove(const K& key) { m_table.remove({ key, V() }); }
|
||||
void remove_one_randomly() { m_table.remove(m_table.begin()); }
|
||||
|
||||
typedef HashTable<Entry, EntryTraits> HashTableType;
|
||||
@ -50,11 +50,11 @@ public:
|
||||
|
||||
IteratorType begin() { return m_table.begin(); }
|
||||
IteratorType end() { return m_table.end(); }
|
||||
IteratorType find(const K&);
|
||||
IteratorType find(const K& key) { return m_table.find({ key, V() }); }
|
||||
|
||||
ConstIteratorType begin() const { return m_table.begin(); }
|
||||
ConstIteratorType end() const { return m_table.end(); }
|
||||
ConstIteratorType find(const K&) const;
|
||||
ConstIteratorType find(const K& key) const { return m_table.find({ key, V() }); }
|
||||
|
||||
void ensure_capacity(int capacity) { m_table.ensure_capacity(capacity); }
|
||||
|
||||
@ -96,42 +96,9 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
HashTable<Entry, EntryTraits> m_table;
|
||||
HashTableType m_table;
|
||||
};
|
||||
|
||||
template<typename K, typename V>
|
||||
void HashMap<K, V>::set(const K& key, V&& value)
|
||||
{
|
||||
m_table.set(Entry { key, move(value) });
|
||||
}
|
||||
|
||||
template<typename K, typename V>
|
||||
void HashMap<K, V>::set(const K& key, const V& value)
|
||||
{
|
||||
m_table.set(Entry { key, value });
|
||||
}
|
||||
|
||||
template<typename K, typename V>
|
||||
void HashMap<K, V>::remove(const K& key)
|
||||
{
|
||||
Entry dummy { key, V() };
|
||||
m_table.remove(dummy);
|
||||
}
|
||||
|
||||
template<typename K, typename V>
|
||||
auto HashMap<K, V>::find(const K& key) -> IteratorType
|
||||
{
|
||||
Entry dummy { key, V() };
|
||||
return m_table.find(dummy);
|
||||
}
|
||||
|
||||
template<typename K, typename V>
|
||||
auto HashMap<K, V>::find(const K& key) const -> ConstIteratorType
|
||||
{
|
||||
Entry dummy { key, V() };
|
||||
return m_table.find(dummy);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using AK::HashMap;
|
||||
|
Loading…
Reference in New Issue
Block a user