|
Algorithms_in_C++ 1.0.0
Set of 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>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.
| int main | ( | void | ) |
|
static |
self test implementations