I have a data structure which has,
<Book title>, <Author>, and <rate>
Since Book title or Author can be duplicated, I’d like to build a composite key.
(let’s say I cannot make extra unique key, such as ID)
Since data is pretty huge, I’m using GCC unordered_map for the sake of speed,
and I built my structure like this:
typedef pair<string, string> keys_t
typedef unordered_map<keys_t, double> map_t;
Everything works okay in general,
But the problem happens when I want to refer one specific key.
For example, let’s suppose I’d like to find the best-rated book among books titled as “math”, or I’d like to find the average rate of “Tolstoy”‘s books.
In this case, this becomes very bothersome, since I cannot only refer only one of the key pair.
I happened to find boost::multi_index but I’m having some trouble understanding the documents.
Does anyone have some idea or guideline for this?
Solution to make multiple indices, succinct example for multi_index, any other approach, etc.. any help will be appreciated.
Thank you.
I figured out how to use
boost::multi_indexI referred this code: Boost multi_index composite keys using MEM_FUN
and here’s my code for your reference.
Thank you all who made comments!