Im having trouble to convert a string vector with size of ~ 1.0000.0000 elements to an associative vector with integers.
Input:
std::vector<std::string> s {"a","b","a","a","c","d","a"};
Desired output:
std::vector<int> i {0,1,0,0,2,3,0};
I was thinking of an std::unordered_multiset
as mentioned in Associative Array with Vector in C++ but i can't get it running.
The goal is to reduce the time it takes to convert c++ strings to R strings, which is so much faster if I just use numbers.
Thank you for your help!
Edit:
Thats how I tried to populate the set:
for (size_t i = 0; i < s.size(); i++)
{
set.insert(s[i]);
}
This code will output your desired output for your given input. And it will process 1.000.000 strings of length 3 in 0.4s. So I think unordered_map is a viable choice.