#ifndef CEPH_SIMPLECACHE_H
#define CEPH_SIMPLECACHE_H
+#include <list>
+#include <map>
+#include <unordered_map>
+#include <utility>
+
#include "common/ceph_mutex.h"
-#include "include/unordered_map.h"
template <class K, class V, class C = std::less<K>, class H = std::hash<K> >
class SimpleLRU {
size_t max_size;
size_t max_bytes = 0;
size_t total_bytes = 0;
- ceph::unordered_map<K, typename list<pair<K, V> >::iterator, H> contents;
- list<pair<K, V> > lru;
- map<K, V, C> pinned;
+ std::unordered_map<K, typename std::list<std::pair<K, V>>::iterator, H> contents;
+ std::list<std::pair<K, V> > lru;
+ std::map<K, V, C> pinned;
void trim_cache() {
while (contents.size() > max_size) {
void clear_pinned(K e) {
std::lock_guard l(lock);
- for (typename map<K, V, C>::iterator i = pinned.begin();
+ for (auto i = pinned.begin();
i != pinned.end() && i->first <= e;
pinned.erase(i++)) {
- typename ceph::unordered_map<K, typename list<pair<K, V> >::iterator, H>::iterator iter =
- contents.find(i->first);
+ auto iter = contents.find(i->first);
if (iter == contents.end())
_add(i->first, std::move(i->second));
else
void clear(K key) {
std::lock_guard l(lock);
- typename ceph::unordered_map<K, typename list<pair<K, V> >::iterator, H>::iterator i =
- contents.find(key);
+ auto i = contents.find(key);
if (i == contents.end())
return;
total_bytes -= i->second->second.length();
bool lookup(K key, V *out) {
std::lock_guard l(lock);
- typename ceph::unordered_map<K, typename list<pair<K, V> >::iterator, H>::iterator i =
- contents.find(key);
+ auto i = contents.find(key);
if (i != contents.end()) {
*out = i->second->second;
lru.splice(lru.begin(), lru, i->second);
return true;
}
- typename map<K, V, C>::iterator i_pinned = pinned.find(key);
+ auto i_pinned = pinned.find(key);
if (i_pinned != pinned.end()) {
*out = i_pinned->second;
return true;