mirror of
https://github.com/RPCS3/rsx_program_decompiler.git
synced 2026-01-31 01:25:19 +01:00
39 lines
710 B
C++
39 lines
710 B
C++
#pragma once
|
|
#include <unordered_map>
|
|
|
|
template<typename InfoType, typename DataType, typename Hasher = InfoType::hash_t, typename Equal = std::equal_to<InfoType>>
|
|
class cache_t
|
|
{
|
|
std::unordered_map<InfoType, DataType, Hasher, Equal> m_entries;
|
|
|
|
public:
|
|
bool invalidate(const InfoType& key)
|
|
{
|
|
if (auto found = m_entries.find(key))
|
|
{
|
|
m_entries.erase(found);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
DataType& entry(const InfoType& key)
|
|
{
|
|
return m_entries[key];
|
|
}
|
|
|
|
const DataType& entry(const InfoType& key) const
|
|
{
|
|
return m_entries.at(key);
|
|
}
|
|
|
|
void each(std::function<void(std::pair<const InfoType, DataType>)> function)
|
|
{
|
|
for (auto &entry : m_entries)
|
|
{
|
|
function(entry);
|
|
}
|
|
}
|
|
};
|