summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Hutchinson <jlhutch@gmail.com>2009-04-12 23:23:32 -0500
committerJay Hutchinson <jlhutch@gmail.com>2009-04-12 23:23:32 -0500
commit1536f6bde597131825e78785494cc463575fbac4 (patch)
treedf9dbfc2c7a317cbb62205512b1ef394c1b4344d
parent5019967c6fb9ac41f0668c8f3f45822886e715ba (diff)
downloadpylru-1536f6bde597131825e78785494cc463575fbac4.tar.gz
Worked on clear() and size() methods.
-rw-r--r--lru.py26
1 files changed, 16 insertions, 10 deletions
diff --git a/lru.py b/lru.py
index 03a9787..8647f33 100644
--- a/lru.py
+++ b/lru.py
@@ -56,7 +56,7 @@ class lrucache:
self.key = None
self.obj = None
-
+
# Initalize the list with 'size' empty nodes. Create the first node and
# assign it to the 'head' variable, which represents the head node in the
@@ -71,12 +71,20 @@ class lrucache:
self.head.next.prev = node
self.head.next = node
+
+ self.listSize = size
def __len__(self):
return len(self.table)
def clear(self):
- self.table.clear()
+ self.table.clear()
+
+ node = self.head
+ for i in range(self.listSize):
+ node.key = None
+ node.obj = None
+ node = node.next
def __contains__(self, key):
return key in self.table
@@ -131,7 +139,7 @@ class lrucache:
# If the node already contains something we need to remove the old key from
# the dictionary.
- if not node.key == None:
+ if node.key is not None:
del self.table[node.key]
# Place the key and the object in the node
@@ -167,19 +175,17 @@ class lrucache:
# even for the case where the 'node' is the 'head' node.
self.mtf(node)
self.head = node.next
-
- return
+
- def size(self, size):
+ def size(self, size=None):
if size is None:
return self.listSize
assert size > 0
-
-
-
+ raise NotImplementedError
+
def __del__(self):
@@ -191,7 +197,7 @@ class lrucache:
tail = self.head.prev
node = self.head
- while node.prev:
+ while node.prev is not None:
node = node.prev
node.next.prev = None