I'd like to define a std::map: map<struct term, vector<size_t.
The definition of the structure is:
struct term {
string word;
size_t freq;
};
the freq is the size() of vector<size_t>.
When I insert the 'term' into the map,
the map should sort the key by the string 'word'.
And later, I need to sort the 'term' by the 'freq'.
I think I can define two compare functions,
one for insertion to the map: map<struct term, vector<size_t>, comp1>
index;
another for a sort function: sort(terms.begin(), terms.end(), comp2).
And now:
1. How can I use map as associative array, that is, how to do
something like:
struct term test;
test.string = "Hello";
test.freq = 0;
index[test].push_back(1);
And after I push_back all the size_t, I need to change the value of
test.freq.
2. I didn't find a function that return all the 'keys' as a vector or
sth like that.
If I define a function take a parameter vector<string>,
how can I match the string with struct term in the map?
I wish I presented my questions clearly.
Thanks,
Stephen Hsu