The algorithm refers to the solution problem accurate and complete description, is the clear instruction to solve the problem, uses the systematic method to describe solves the problem the strategy mechanism.
LRU is one of the algorithms, so how to use Python to implement an LRU-based algorithm?
This blog post is about using Python to implement a cache based on the LRU algorithm.
Cache
As you can tell, when you enter the information you want to search in the input box of your browser, the browser sends a request to the server, and the server passes a series of operations before returning the data to the browser.
But if there are many browsers to access at the same time, then there will be a lot of repeated operations. This will cause waste of resources, waste of time, causing the lag, which is obviously not what we want.
LRU algorithm
Commonly used in page replacement algorithms, is for virtual page Storage Management Services.
Elimination Logic:
The cache is a list structure, and each space represents a cache capacity, which is obviously 8. The top and the end are a node, respectively, the head and tail.
When the number of data accesses increases, it is constantly being moved to the head of the list, with very little data being accessed, and the cache is squeezed.
20 Line Python code implementation LRU algorithm
Is the Python algorithm difficult? Difficult, but not as close to your fingertips. We can start from the easy, then the road will be more and more wide.
Big Coffee 20 Line Python code to play the algorithm! Is it difficult to relate to algorithms? Subvert cognition!