TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Implementation for [LRU Cache] (https://en.wikipedia.org/wiki/Cache_replacement_policies#:~:text=Least%20Recently%20Used%20(LRU)) More...
#include <cassert>
#include <cstdint>
#include <iostream>
#include <unordered_map>
Go to the source code of this file.
Classes | |
class | others::Cache::D_Node< T > |
Node for a doubly linked list with data, prev and next pointers. More... | |
class | others::Cache::LRUCache< K, V > |
LRUCache. More... | |
Namespaces | |
namespace | others |
for vector | |
namespace | others::Cache |
Cache algorithm. | |
Functions | |
static void | test () |
self test implementations | |
int | main () |
main function | |
Implementation for [LRU Cache] (https://en.wikipedia.org/wiki/Cache_replacement_policies#:~:text=Least%20Recently%20Used%20(LRU))
LRU discards the least recently used value. Data structures used - doubly linked list and unordered_map
unordered_map maps the key to the address of the node of the linked list. If the element is accessed, the element is moved to the beginning of the linked list.
When the cache is full, the last element in the linked list is popped.
Definition in file lru_cache2.cpp.
int main | ( | void | ) |
main function
Definition at line 274 of file lru_cache2.cpp.
|
static |
self test implementations
Definition at line 220 of file lru_cache2.cpp.