C++ design: How to cache most recent used

前端 未结 10 1418
走了就别回头了
走了就别回头了 2021-02-09 12:21

We have a C++ application for which we try to improve performance. We identified that data retrieval takes a lot of time, and want to cache data. We can\'t store all data in mem

10条回答
  •  深忆病人
    2021-02-09 13:22

    I believe this is a good candidate for treaps. The priority would be the time (virtual or otherwise), in ascending order (older at the root) and the long as the key.

    There's also the second chance algorithm, that's good for caches. Although you lose search ability, it won't be a big impact if you only have 1000 items.

    The naïve method would be to have a map associated with a priority queue, wrapped in a class. You use the map to search and the queue to remove (first remove from the queue, grabbing the item, and then remove by key from the map).

提交回复
热议问题