Now, when we new up a Cache instance, we'll want certain things predefined in the constructor. Let's flesh that out:
- We'll need a reference to the capacity
- A
countfor the number of keys we have - The
cachevia a hash table itself - References to the heads and tails of the doubly linked list
1class Cache:
2 def __init__(capacity):
3 self.count = 0
4 self.capacity = capacity
5 self.cache = {}
6 self.head = DLinkedNode()
7 self.head.pre = null
8 self.tail = DLinkedNode()
9 self.tail.next = None
10 self.head.next = self.tail
11 self.tail.pre = self.head