File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed
Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change 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 {
1010public:
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
1919private:
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
You can’t perform that action at this time.
0 commit comments