Skip to content

Commit 9fc08f2

Browse files
authored
Update LFUCache.h
1 parent 99abbee commit 9fc08f2

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

include/LFUCache.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
#ifndef LRUCACHE_H
2-
#define LRUCACHE_H
1+
#ifndef LFUCACHE_H
2+
#define LFUCACHE_H
33

44
#include <unordered_map>
55
#include <list>
66
#include <mutex>
77
#include <atomic>
88

9-
class LRUCache {
9+
class LFUCache {
1010
public:
11-
LRUCache(size_t capacity);
11+
LFUCache(size_t capacity);
1212
int get(int key);
1313
void put(int key, int value);
1414

@@ -17,17 +17,17 @@ class LRUCache {
1717
void resetStats();
1818

1919
private:
20-
void moveToFront(int key);
20+
void touch(int key);
2121
void evict();
2222

2323
size_t capacity;
24-
std::unordered_map<int, std::pair<int, int>> cache;
25-
std::list<int> access_order;
24+
std::unordered_map<int, std::pair<int, int>> cache; // key -> {value, frequency}
25+
std::unordered_map<int, std::list<int>> freq_map; // frequency -> list of keys
2626
std::mutex cache_mutex;
2727

2828
// --- New Stats Counters ---
2929
std::atomic<size_t> hits;
3030
std::atomic<size_t> accesses;
3131
};
3232

33-
#endif // LRUCACHE_H
33+
#endif // LFUCACHE_H

0 commit comments

Comments
 (0)