servo / uluru

A simple, fast, LRU cache implementation.
Mozilla Public License 2.0
191 stars 20 forks source link

Access to item by index #19

Closed dotcypress closed 3 years ago

dotcypress commented 3 years ago

New method added to access item in LRU list by index.

This feature is useful for traverse list in least-recently-used order.

mbrubeck commented 3 years ago

Traversing the list could be done more efficiently by providing an iterator, like in some older versions of this crate:

https://docs.rs/uluru/0.2.0/uluru/struct.LRUCache.html#method.iter

Would this work for your use case?

mbrubeck commented 3 years ago

Ah, it looks like you need to go both backward and forward, so an iterator alone won't work. This seems fine.

mbrubeck commented 3 years ago

This has been published in uluru 2.1.0.

I also added a .iter() method, so cache.get(i) is now equivalent to cache.iter().nth(i).

dotcypress commented 3 years ago

Awesome! Thank you @mbrubeck for quick response!