std::unordered_map<uint64_t, std::list<uint64_t>::iterator>
100uint64_t lastPage =
cache.back();
113 cache.push_front(page);
122 for(uint64_t &it :
cache) {
123std::cout << it <<
" ";
125std::cout << std::endl;
148template<
typenameT>
151std::cout <<
"[TESTS] : ---> "<< msg << std::endl;
161uint64_t expected_hits = 2;
162uint64_t expected_pageFault = 4;
164 log(
"Running Test-1...");
174 log(
"Checking assert statement...");
175assert(cache.
getHits() == expected_hits &&
177 log(
"Assert successful!");
178 log(
"Test-1 complete!");
188uint64_t expected_hits = 4;
189uint64_t expected_pageFault = 2;
191 log(
"Running Test-2...");
201 log(
"Checking assert statement...");
202assert(cache.
getHits() == expected_hits &&
204 log(
"Assert successful!");
205 log(
"Test-2 complete!");
215uint64_t expected_hits = 1;
216uint64_t expected_pageFault = 5;
218 log(
"Running Test-3...");
228 log(
"Checking assert statement...");
229assert(cache.
getHits() == expected_hits &&
231 log(
"Assert successful!");
232 log(
"Test-3 complete!");
244 log(
"TESTS COMPLETED!");
266std::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.
int main()
Main function.
Implementation of the LRU caching algorithm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4