diff options
author | Jay Hutchinson <jlhutch@gmail.com> | 2009-04-09 12:02:59 -0500 |
---|---|---|
committer | Jay Hutchinson <jlhutch@gmail.com> | 2009-04-09 12:02:59 -0500 |
commit | 2866e1cdff68066d21f17e405da3820048f84bf2 (patch) | |
tree | 78b1658d03354a0dc7419ce7445b80c6f79997c5 | |
parent | d948d3283eb05a030b2af71a8a30ea30fa42c57e (diff) | |
download | pylru-2866e1cdff68066d21f17e405da3820048f84bf2.tar.gz |
Added a few simple methods.
-rw-r--r-- | lru.py | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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 |