52#include <unordered_map>
71 std::unordered_map<uint64_t, std::list<uint64_t>::iterator>
100 uint64_t lastPage =
cache.back();
113 cache.push_front(page);
122 for (uint64_t &it :
cache) {
123 std::cout << it <<
" ";
125 std::cout << std::endl;
151 std::cout <<
"[TESTS] : ---> " << msg << std::endl;
161 uint64_t expected_hits = 2;
162 uint64_t expected_pageFault = 4;
164 log(
"Running Test-1...");
174 log(
"Checking assert statement...");
175 assert(cache.
getHits() == expected_hits &&
177 log(
"Assert successful!");
178 log(
"Test-1 complete!");
188 uint64_t expected_hits = 4;
189 uint64_t expected_pageFault = 2;
191 log(
"Running Test-2...");
201 log(
"Checking assert statement...");
202 assert(cache.
getHits() == expected_hits &&
204 log(
"Assert successful!");
205 log(
"Test-2 complete!");
215 uint64_t expected_hits = 1;
216 uint64_t expected_pageFault = 5;
218 log(
"Running Test-3...");
228 log(
"Checking assert statement...");
229 assert(cache.
getHits() == expected_hits &&
231 log(
"Assert successful!");
232 log(
"Test-3 complete!");
244 log(
"TESTS COMPLETED!");
253 lru_tests::run_tests();
266 std::cout <<
"Hits: " << cache.
getHits()
uint64_t pageFrame
Page frame, or total size of the cache.
std::list< uint64_t > cache
Cache linked list (using the STL)
LRUCache(uint64_t pf)
Constructor, Initialize thee LRU class with page frame.
uint64_t hits
was found in cache.
uint64_t getPageFault() const
A function to get page fault.
void refer(uint64_t page)
Refer to a page, or request a page from memory.
uint64_t getHits() const
A function to get page hits.
std::unordered_map< uint64_t, std::list< uint64_t >::iterator > pageMap
Hash map containing pages and their addresses.
void display()
A function to display the current cache.
static void test_3()
A simple test case The assert statement will check expected hist and miss to resultant hits and miss.
void log(T msg)
A function to print given message on console.
static void test_2()
A test case contains hits more than cache size The assert statement will check expected hist and miss...
static void test_1()
A simple test case The assert statement will check expected hist and miss to resultant hits and miss.
static void run_tests()
A function to invoke all test cases.
Implementation of the LRU caching algorithm