1
0
mirror of https://github.com/donnemartin/system-design-primer.git synced 2025-06-12 21:47:33 +02:00

Convert all .py files to be valid Python (#98)

This commit is contained in:
cclauss
2018-03-07 01:37:46 +01:00
committed by Donne Martin
parent 3ca1f1d0d2
commit f099a0ad3f
7 changed files with 78 additions and 39 deletions

View File

@ -11,9 +11,14 @@ class LinkedList(object):
self.head = None
self.tail = None
def move_to_front(self, node): # ...
def append_to_front(self, node): # ...
def remove_from_tail(self): # ...
def move_to_front(self, node):
pass
def append_to_front(self, node):
pass
def remove_from_tail(self):
pass
class Cache(object):
@ -26,7 +31,7 @@ class Cache(object):
def get(self, query)
"""Get the stored query result from the cache.
Accessing a node updates its position to the front of the LRU list.
"""
node = self.lookup[query]
@ -37,7 +42,7 @@ class Cache(object):
def set(self, results, query):
"""Set the result for the given query key in the cache.
When updating an entry, updates its position to the front of the LRU list.
If the entry is new and the cache is at capacity, removes the oldest entry
before the new entry is added.
@ -58,4 +63,4 @@ class Cache(object):
# Add the new key and value
new_node = Node(results)
self.linked_list.append_to_front(new_node)
self.lookup[query] = new_node
self.lookup[query] = new_node