Skip to content

Commit

Permalink
Add link to post.
Browse files Browse the repository at this point in the history
Change-Id: Icc3a6eaa8c4c1cf092d479aa2ef686f463b58a8c
  • Loading branch information
laurentluce committed Jun 10, 2015
1 parent d9cb5a7 commit d3c75bb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -27,3 +27,5 @@ Cache with LFU eviction scheme implemented in Python with complexity O(1) for in
1: ['k3']
2: ['k2']
```

More details: http://www.laurentluce.com/posts/least-frequently-used-cache-eviction-scheme-with-complexity-o1-in-python
4 changes: 2 additions & 2 deletions post.txt
Expand Up @@ -135,7 +135,7 @@ class Cache(DoublyLinkedList):

Next step is to define methods to insert to the cache, access the cache and delete from the cache.

Let's look at the insert method logic. It takes a key and a value, for example HTTP request and response. If the frequency node with frequency one does not exist, it is inserted at the beginning of the access frequency linked list. An item node is added to the frequency node items linked list. The key and value are added to the dictionary. Complexity is O(1).
Let's look at the insert method logic. It takes a key and value, for example HTTP request and response. If the frequency node with frequency one does not exist, it is inserted at the beginning of the access frequency linked list. An item node is added to the frequency node items linked list. The key and value are added to the dictionary.

[code lang="python"]
def insert(self, key, value):
Expand All @@ -153,7 +153,7 @@ We insert two elements in our cache, we end up with:

<img src="/images/blog/lfu/insert.png" alt="LFU insert method.">

Let's look at the access method logic. If the key does not exist, we raise an exception. If the key exists, we move the item node to the frequency node list with frequency + 1 (adding the frequency node if it does not exist). Complexity is O(1).
Let's look at the access method logic. If the key does not exist, we raise an exception. If the key exists, we move the item node to the frequency node list with frequency + 1 (adding the frequency node if it does not exist).

[code lang="python"]
def access(self, key):
Expand Down

0 comments on commit d3c75bb

Please sign in to comment.