Add non-template access methods to util::hash_table
This commit is contained in:
parent
645423ecba
commit
153cc87986
1 changed files with 33 additions and 0 deletions
|
|
@ -386,12 +386,22 @@ namespace psemek::util
|
||||||
return {result.first.as_const(), result.second};
|
return {result.first.as_const(), result.second};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iterator find(T const & key) const
|
||||||
|
{
|
||||||
|
return impl_.find(key).as_const();
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Key>
|
template <typename Key>
|
||||||
iterator find(Key const & key) const
|
iterator find(Key const & key) const
|
||||||
{
|
{
|
||||||
return impl_.find(key).as_const();
|
return impl_.find(key).as_const();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool contains(T const & key) const
|
||||||
|
{
|
||||||
|
return find(key) != end();
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Key>
|
template <typename Key>
|
||||||
bool contains(Key const & key) const
|
bool contains(Key const & key) const
|
||||||
{
|
{
|
||||||
|
|
@ -497,6 +507,13 @@ namespace psemek::util
|
||||||
return impl_.end();
|
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>
|
template <typename Key1>
|
||||||
Value & operator[] (Key1 const & key)
|
Value & operator[] (Key1 const & key)
|
||||||
{
|
{
|
||||||
|
|
@ -505,6 +522,14 @@ namespace psemek::util
|
||||||
return insert({Key(key), Value{}}).first->second;
|
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>
|
template <typename Key1>
|
||||||
Value & at(Key1 const & key)
|
Value & at(Key1 const & key)
|
||||||
{
|
{
|
||||||
|
|
@ -514,6 +539,14 @@ namespace psemek::util
|
||||||
return it->second;
|
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>
|
template <typename Key1>
|
||||||
Value const & at(Key1 const & key) const
|
Value const & at(Key1 const & key) const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue