资 源 简 介
A C++ implementation of an LRU cache that has a maximum size (but no expiration time). The cache is implemented as a single hash table and provides fast, constant-time insertion, retrieval and query operations.
Usage
```
#include
#include "lru.hpp"
using namespace std;
int compute_value(int key)
{
return 100 + key;
}
int main()
{
// Create a cache that can hold 10 (int, int) pairs at most
typedef plb::LRUCacheH4 lru_cache;
lru_cache cache(10);
// Insert a (key, value) pair into the cache: same syntax as std::map
cache[1] = compute_value(1);
for (int key = 1; key <= 2; ++key) {
// Query the cache: Does it contain the key?
lru_cache::const_iterator it = cache.find(key);
if (it != cache.end()) {
// Key found: retrieve its associated value
cout << "retrieving: " << it.key() << " -> " << it.value() << end