File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed
Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change 44#include < unordered_map>
55#include < list>
66#include < mutex>
7+ #include < atomic>
78
89class LRUCache {
910public:
10- LRUCache (int capacity);
11+ LRUCache (size_t capacity);
1112 int get (int key);
1213 void put (int key, int value);
1314
15+ // --- New Methods for Stats ---
16+ double getHitRate () const ;
17+ void resetStats ();
18+
1419private:
1520 void moveToFront (int key);
1621 void evict ();
1722
18- int capacity;
19- std::unordered_map<int , std::pair<int , int >> cache; // key -> (value)
20- std::list<int > access_order; // order of keys (most recent to least)
23+ size_t capacity;
24+ std::unordered_map<int , std::pair<int , int >> cache;
25+ std::list<int > access_order;
2126 std::mutex cache_mutex;
27+
28+ // --- New Stats Counters ---
29+ std::atomic<size_t > hits;
30+ std::atomic<size_t > accesses;
2231};
2332
2433#endif // LRUCACHE_H
You can’t perform that action at this time.
0 commit comments