[Python-ideas] Contiguous-array-based ordering for OrderedDict
Serhiy Storchaka
storchaka at gmail.com
Sat Dec 12 20:16:00 EST 2015
On 13.12.15 02:27, Guido van Rossum wrote:
> I'm not following this thread all that closely, but am I the only one
> who thinks that the LRU cache (discussed in another thread) could be
> implemented with much less code on top of OrderedDict? Basically
> whenever you access a key you just move it to the front, and when you
> add a key when it is already at capacity you delete the first one.
I have doubts about this. First, an ordered dictionary is only a part of
the LRU cache implementation, using OrderedDict wouldn't make the code
much less. Second, the LRU cache needs only small and very limited part
of OrderedDict, with different requirements to reentrancy,
thread-safety, and errors handling (partially more strong, partially
more lenient). The code currently used by the LRU cache is much simpler,
likely faster, and more bug-free.
More information about the Python-ideas
mailing list