3 ms·
You could have used std::list iterators instead of raw pointers to a node in the map to implement that.
by en4bz 10y ago
You could have used std::list iterators instead of raw pointers to a node in the map to implement that.
- mohaps 10y agoyeah, saw the gist posted by quinnftw. that actually is a better way to do what I'm doing. Will update that along with the cache.remove(const Key& k, F deleteCallback) method. Thanks for the feedback
- mohaps 10y agonow i remember why I went with the old linked list implementation. with the std::list, everytime I refreshed a node... i did a copy. basically to the tune of list.push_back(*iter) where as I wanted to keep it as a simple unlink and relink of the node copy of the comment: https://news.ycombinator.com/item?id=12391069 https://news.ycombinator.com/item?id=12391069
- en4bz 10y agoTo swap nodes in the list you need to use splice like this: keys_.splice(keys_.begin(), keys_, iter->second); Where iter is from the cache lookup.