Using pure STL, I am trying to apply the LFU (at least frequent usage) cache (I do not want to use Boost!)
).
There are requirements:
- Affiliate access to an element by using
std :: map as the
key .
- Ability to update priority (
UsesCount )
- Issuing low priority item (using its
UsesCount attribute) Qualification of
There are problems:
- If I use
std :: vector as the container of the item (
associate ,
value ,
UsesCount ),
std :: map as the container for vector and priority within the vector for access As the implementation of the queue, code> standard :: make-up ,
std :: push_heap and
std :: pop_heap are not valid < Li> If I use
std :: list (or
std :: map ) instead of
, std :: vector previous In Nfigreshn,
std :: make_heap etc. can not be collected does not support because of their iterators aritmetic.
- If I want to use
std :: priority_queue , I do not have the ability to update the item's priority.
The questions are:
- Can I clarify something to solve this problem?
- Can you apply the previous requirements of LFU Cash Meeting as an example for some pure C ++ / STL?
Thank you for your insights.
* _ heap works and a vector looks a good fit. However this will result in slow updates. The problem about the invalid iter that you encounter for every container using a vector in the form of the underlying data structure is common. It has been taken from this point of view, but for the reason mentioned above it does not provide an inappropriate interface. Provide the ability to update other piles.
Something that looks a bit strange: Even if you can use
std :: priority_queue , you still will encounter recurrent invalid problems.
To answer your questions directly: You are missing something clear.
std :: priority_queue is not as useful as it should be. The best way is to write your own stack implementation that supports the update. It is a difficult task to make STL compatible (especially allotant conscious) and it is not easy. On top of that, implement the LFU cache.
See Boost implementation to get an idea of the effort for the first step. I do not know of any reference implementation for the other.
To work around Iterator invalid you can always choose indirection in any other container, although you should try to avoid it because it creates an extra cost and becomes quite dirty.
- If I want to use
- Ability to update priority (
Comments
Post a Comment