Use a std::array internally as we don't expect the cache to be
copied a lot. The test case is also greatly expanded to test the
full (new) API surface of this new container class.
Details
Diff Detail
- Repository
- R865 Ruqola
- Lint
Automatic diff as part of commit; lint not applicable. - Unit
Automatic diff as part of commit; unit tests not applicable.
Cool stuff, but...
LRUCache and its predecessor PixmapCache seem to disagree on the meaning of "Used" in LRU.
Only LRUCache::insert counts as "using", while PixmapCache was marking the entry as "used" also in findCachedPixmap().
The goal was: if we keep viewing the same pixmap then we shouldn't evict it. Imagine switching between 6 channels, all of which happen to show one pixmap. If you switch A, B, A, C, A, D, A, E, A, F then LRUCache would evict the A pixmap once reaching F, because it was *inserted* before all others. It seems to me that B should be evicted, instead (least recently viewed, not least recently inserted) .
src/core/lrucache.h | ||
---|---|---|
61 | Can you add a unittest for find() on an empty container? I sense problems.... | |
67 | is rotate the right thing to do? It affects all other entries and might send the "previously most recently used" entry all the way to the back of the list, no? Shouldn't this be a remove-and-prepend? | |
68 | remove it = since the value isn't used? |
src/core/lrucache.h | ||
---|---|---|
61 | OK. I thought calling rbegin() on an empty container was invalid, but I was wrong. | |
67 | https://en.cppreference.com/w/cpp/algorithm/rotate // simple rotation to the left std::rotate(v.begin(), v.begin() + 1, v.end()); (value before): 0 1 2 2 3 4 5 7 7 10 simple rotate left : 1 2 2 3 4 5 7 7 10 0 |
fixup the rotate call, thanks! also expanded the test to catch this
see also: https://cpp.godbolt.org/z/Aj7Yjv