From: John H. <jdh...@ac...> - 2005-01-24 23:09:06
|
>>>>> "Fernando" == Fernando Perez <Fer...@co...> writes: Fernando> Just a minor comment: insert(0) is an expensive (O(N)) Fernando> operation on lists. This kind of problem might be better Fernando> addressed with a deque Fernando> (http://www.python.org/dev/doc/devel/lib/module-collections.html, Fernando> could be backported to py2.3). If I read the patch correctly, usage_stack is being used as a simple counter. I think the data structure we want is a class derived from dict that pops elements off (preferably intelligently, ie pops the ones which haven't been accessed in a while) when the dict length gets too long. In other words, we don't need to structures (cached and usage_stack) to do the work of one There must be such a beast in the cookbook or elsewhere, a cache object which works like a dict but has a max size... JDH |