Add non-template access methods to util::hash_table

This commit is contained in:
Nikita Lisitsa 2024-03-12 20:29:29 +03:00
parent 645423ecba
commit 153cc87986

View file

@ -386,12 +386,22 @@ namespace psemek::util
return {result.first.as_const(), result.second};
}
iterator find(T const & key) const
{
return impl_.find(key).as_const();
}
template <typename Key>
iterator find(Key const & key) const
{
return impl_.find(key).as_const();
}
bool contains(T const & key) const
{
return find(key) != end();
}
template <typename Key>
bool contains(Key const & key) const
{
@ -497,6 +507,13 @@ namespace psemek::util
return impl_.end();
}
Value & operator[] (Key const & key)
{
if (auto it = find(key); it != end())
return it->second;
return insert({Key(key), Value{}}).first->second;
}
template <typename Key1>
Value & operator[] (Key1 const & key)
{
@ -505,6 +522,14 @@ namespace psemek::util
return insert({Key(key), Value{}}).first->second;
}
Value & at(Key const & key)
{
auto it = find(key);
if (it == end())
throw util::key_error{key};
return it->second;
}
template <typename Key1>
Value & at(Key1 const & key)
{
@ -514,6 +539,14 @@ namespace psemek::util
return it->second;
}
Value const & at(Key const & key) const
{
auto it = find(key);
if (it == end())
throw util::key_error{key};
return it->second;
}
template <typename Key1>
Value const & at(Key1 const & key) const
{