Fixed Time Efficient Least Frequently Used Cache
agentultra.com·5h
🔮Prefetching
Preview
Report Post

In the last post I wanted to demonstrate how to implement a time-efficient Least Frequently Used cache in C++23 using doubly-linked lists. While the idea and the approach was right, the implementation was not, and we ended up with O(n) operations (again) instead of the promised, O(1).

Here’s the annotated implementation so you can see where the problem is:

#include <cassert>
#include <cstddef>
#include <cstdint>
#include <iterator>
#include <list>
#include <map>
#include <optional>
#include <print>
#include <ranges>

template <typename K, typename V> struct CacheValue {
K key;
V value;
uint64_t freq_count;

// There's a problem with this struct...
auto operator<=>(const CacheValue<K, V>&) const = def...

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help