-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Core::FIFOCache #79
base: master
Are you sure you want to change the base?
Conversation
src/Core/FIFOCache.hh
Outdated
|
||
template<typename Key, typename Value, typename Hash, typename KeyEqual> | ||
Value& FIFOCache<Key, Value, Hash, KeyEqual>::get(const Key& key) { | ||
return cacheMap_.at(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This throws an exception if the key is not present. As nobody ever catches these it will probably terminate the application. I think it would be better to return std::optional<Value&>
and for an interface the default-constructs the value add an operator[]
function.
For the version returning std::optional<Value&>
we could also have a const version of the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C++ unfortunately doesn't support optional references so std::optional<Value&>
doesn't work . I have implemented this now by using std::optional<std::reference_wrapper<Value>>
. It could also be done by using Value*
as return value instead and returning nullptr
when the key is not found.
PS: same comment about adding |
Cache based on an unordered_map with a maximum size such that when the cache is full and
a new item is trying to be added, the oldest item in the cache gets removed.
Note: oldest is determined by order of insertion, not order of last access.
Example: