473,320 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

LRU cache (and other things missing from the standard library ...)

I recently implemented a LRU cache. And I wondered why such a useful class is
not already in the standard library. The only thing I found was a cookbook
entry but the comments said it was problematic.

Btw. my implementation is currently at
http://initd.org/svn/initd/pysqlite/trunk/misc/lru.py Does anybody see any
problems with this code?

I've already started translating it into C (*) , which speeds it up by between
factor 5 to 8. Maybe a candidate for the standard library once it's finished?

-- Gerhard

(*) http://initd.org/svn/initd/pysqlite/trunk/src/cache.c is the first iteration.
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBhoTedIO4ozGCH14RAnfvAJ9bhKGHNf9zoK0NwzOFTu E+Is8Z3gCghTt6
sCNUY0zLg6C9V29PEw+sUFc=
=pJS6
-----END PGP SIGNATURE-----

Jul 18 '05 #1
1 1407
Gerhard Haering <gh@ghaering.de> writes:
I recently implemented a LRU cache. And I wondered why such a useful class is
not already in the standard library. The only thing I found was a cookbook
entry but the comments said it was problematic.
[...]
I've already started translating it into C (*) , which speeds it up by between
factor 5 to 8. Maybe a candidate for the standard library once it's finished?


Would this be a suitable addition for the collections module (which
currently only has deque in it)?

I'm not sure if a LRU cache counts as a "collection" in that sense. I
looked at the code briefly, but don't really follow it yet...

Paul.
--
One of the lessons of history is that nothing is often a good thing to
do and always a clever thing to say. -- Will Durant
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: ernst.stiegler | last post by:
Hello, I just want to read a whole line from a console input. What I don't understand is that I always have to press ENTER twice in order to see the line I've entered. Here's my code : ...
11
by: Steven T. Hatton | last post by:
In the past there have been lengthy discussiions regarding the role of header files in C++. People have been very adamat about header files serving as in interface to the implementation. I do...
59
by: seberino | last post by:
I've heard 2 people complain that word 'global' is confusing. Perhaps 'modulescope' or 'module' would be better? Am I the first peope to have thought of this and suggested it? Is this a...
81
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there...
4
by: Guadala Harry | last post by:
I want to create a STATIC method that removes all items from the Cache. Questions: 1. Is a safe thing to do (any threading issues?) 2. Is the following code a good way to get the job done -...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
17
by: Kevin Hall | last post by:
C++ is one of my favorite languages to work in. This is because it has so many differrent strengths. But there is also a number of blemishes in the language -- some could potentially be fixed,...
5
by: =?iso-8859-1?B?TWF0dGlhcyBCcuRuZHN0cvZt?= | last post by:
Hello! I have a question about filecmp.cmp(). The short code snippet blow does not bahave as I would expect: import filecmp f0 = "foo.dat" f1 = "bar.dat"
73
by: Yevgen Muntyan | last post by:
Hey, I was reading C99 Rationale, and it has the following two QUIET CHANGE paragraphs: 6.5.3.4: "With the introduction of the long long and extended integer types, the sizeof operator may...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.