0
Vector to set effective way and for map
Hi I am having an idea that option 1 to convert vector from set is effective compared to option 2. Can I have reason of this effectiveness for option 1? Same way, is it possible to convert vector to map effectively rather than pushing one element one by one? If not, is it good option to insert value in map in place of sorting ? Now sorting also takes n*log n and map insertion also take log n * n. https://sololearn.com/compiler-playground/cua4WRWxiK1v/?ref=app
5 ответов
+ 2
Then just use any of the methods you proposed. No need to obsess on optimizing a system that is not optimized in the first place.
Find other places where actual optimizations are relevant. Avoid micro-optimizations with minimal gains.
+ 1
Why start with a vector if you ultimately want a multiset?
multiset<int> st{1,3,4,2,6,8,9,7,5,1,1,1};
for(auto num : st)
cout << num << ",";
cout << endl;
or use <algorithm> 's sort if you want to sort it.
#include <algorithm>
sort(vec.begin(),vec.end());
+ 1
Ketan Lalcheta
'deteriorate'...😸 is probably right when you try to 'improve' a bad system.
ok, the methods you gave seems to be the standard way of doing it. Maybe some other members here can come up with more efficient ways to do it.
You should also consider the balance of maintainability vs optimization. Highly optimized codes are often harder to understand and maintain. They can also affect the compiler's ability to further optimize your code.
0
Its not about what we start with. Sometimes , it is not in your control. You have output in vector form from some functionality and need it in map format. So what to do there as you cant change already available code at so many places
0
Could not agree more Bob_Li I am not looking for existing system optimization. What I am concerned is about code I am writing now. If there is some good option to use which is optimized , why Should I use bad version of conversion from vector to map? Bad existing system does not give me free hand to deteriorate it more.