Skip to content

Commit 99abbee

Browse files
authored
Update LRUCache.h
1 parent 7805016 commit 99abbee

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

include/LRUCache.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,30 @@
44
#include <unordered_map>
55
#include <list>
66
#include <mutex>
7+
#include <atomic>
78

89
class LRUCache {
910
public:
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+
1419
private:
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

0 commit comments

Comments
 (0)