#pragma once
#include "LRUCache.h"
class SLRU
{
public:
SLRU(int pro_size, int eli_size) :protectLRU( pro_size ), eliminateLRU(eli_size) {
}
~SLRU(){}
void put(std::string key, int value)
{
int value_pro = protectLRU.get(key);
if (value_pro != -1)
{
protectLRU.put(key, value);
return;
}
eliminateLRU.put(key, value);
}
int get(std::string key)
{
int value = eliminateLRU.get(key);
int value_pro = protectLRU.get(key);
if (value_pro != -1)
{
return value_pro;
}
if (value != -1)
{
std::pair<std::string, int> res = protectLRU.put(key, value);
if (!res.first.empty())
{
eliminateLRU.put(res.first, res.second);
}
}
return value;
}
private:
LRUCache<std::string, int> protectLRU;
LRUCache<std::string, int> eliminateLRU;
};
SLRU c++实现(附LRU实现)
于 2023-11-05 10:37:38 首次发布