summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Hutchinson <jlhutch@gmail.com>2009-04-09 12:02:59 -0500
committerJay Hutchinson <jlhutch@gmail.com>2009-04-09 12:02:59 -0500
commit2866e1cdff68066d21f17e405da3820048f84bf2 (patch)
tree78b1658d03354a0dc7419ce7445b80c6f79997c5
parentd948d3283eb05a030b2af71a8a30ea30fa42c57e (diff)
downloadpylru-2866e1cdff68066d21f17e405da3820048f84bf2.tar.gz
Added a few simple methods.
-rw-r--r--lru.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/lru.py b/lru.py
index 87881bb..a08c85f 100644
--- a/lru.py
+++ b/lru.py
@@ -3,7 +3,7 @@
# Cache implementaion with a Least Recently Used (LRU) replacement policy and a
# basic dictionary interface.
-# Copyright (C) 2006 Jay Hutchinson
+# Copyright (C) 2006, 2009 Jay Hutchinson
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
@@ -36,6 +36,8 @@
class lrucache:
def __init__(self, size):
+
+ assert size > 0
# Initialize the hash table as empty.
self.table = {}
@@ -71,6 +73,11 @@ class lrucache:
self.head.next.prev = node
self.head.next = node
+ def __len__(self):
+ return len(self.table)
+
+ def clear(self):
+ self.table.clear()
def __contains__(self, key):
return key in self.table