summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Hutchinson <jlhutch@gmail.com>2009-04-13 00:25:29 -0500
committerJay Hutchinson <jlhutch@gmail.com>2009-04-13 00:25:29 -0500
commit81a18482848a57b8e8fb5df2cbe7ab8b90be2f94 (patch)
tree1e46d4c6c0d912d404cb2a6e7603805a9d6da9fd
parent1536f6bde597131825e78785494cc463575fbac4 (diff)
downloadpylru-81a18482848a57b8e8fb5df2cbe7ab8b90be2f94.tar.gz
Added inital implementation of add/remove tail node methods.
-rw-r--r--lru.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/lru.py b/lru.py
index 8647f33..a8742df 100644
--- a/lru.py
+++ b/lru.py
@@ -186,7 +186,39 @@ class lrucache:
assert size > 0
raise NotImplementedError
+ def addTailNode(self):
+ raise NotImplementedError
+
+ node = _dlnode()
+ node.next = self.head
+ node.prev = self.head.prev
+
+ self.head.prev.next = node
+ self.head.prev = node
+
+ self.listSize += 1
+
+ def removeTailNode(self):
+ raise NotImplementedError
+
+ assert self.listSize > 1 # Invarient
+ node = self.head.prev
+ if node.key is not None:
+ del self.table[node.key]
+
+ # Splice the tail node out of the list
+ self.head.prev = node.prev
+ node.prev.next = self.head
+
+ self.listSize -= 1
+
+ node.prev = None
+ node.next = None
+
+ node.key = None
+ node.obj = None
+
def __del__(self):
# When we are finished with the cache, special care is taken to break the