Linked Questions
14 questions linked to/from Choosing between std::map and std::unordered_map
564 votes
15 answers
338k views
Is there any advantage of using map over unordered_map in case of trivial keys?
A recent talk about unordered_map in C++ made me realize that I should use unordered_map for most cases where I used map before, because of the efficiency of lookup ( amortized O(1) vs. O(log n) ). ...
100 votes
10 answers
101k views
Super high performance C/C++ hash map (table, dictionary) [closed]
I need to map primitive keys (int, maybe long) to struct values in a high-performance hash map data structure. My program will have a few hundred of these maps, and each map will generally have at ...
18 votes
1 answer
24k views
Why is std::unordered_map slow, and can I use it more effectively to alleviate that?
I’ve recently found out an odd thing. It seems that calculating Collatz sequence lengths with no caching at all is over 2 times faster than using std::unordered_map to cache all elements. Note I did ...
8 votes
5 answers
11k views
Problems using a map with a bitset as a key
I am trying to create a map in C++ with bitset as a key. However the compiler generates the following error messages In file included from /usr/include/c++/4.6/string:50:0, from /usr/...
6 votes
2 answers
22k views
C++ get index of element of array by value
So far, I have been storing the array in a vector and then looping through the vector to find the matching element and then returning the index. Is there a faster way to do this in C++? The STL ...
6 votes
2 answers
6k views
Mapping objects as key with unordered_map
I have a simple Observable class, implementing the observer pattern. This class maps a template type Event to registered observers. This is all fine, though instead of std::map I'd like to use std::...
5 votes
2 answers
4k views
Does MFC CMap have a good performance compared to std::unordered_map or std::map
Does MFC CMap have a good performance compared to std::unordered_map or std::map, I ask this question because I'm going to start a project in my company, and to accelerate the development I'm going a ...
2 votes
3 answers
2k views
"Empty" array\vector members c++
I have to fill an array of 1000 objects by reading data from disk. However, not every objects exits. Once I declare an array, memory will be reserved for 1000 objects. As I read them one by one, I ...
1 vote
2 answers
2k views
How to optimize heavy map insertion in C++ regarding CPU and memory
I am iterating a map where I need to add elements on that map depending on a condition that an element is not found (it could be any other condition). My main problem is that with a big scale of ...
0 votes
1 answer
2k views
How to search the value from a std::map when I use cuda?
I have something stored in std::map, which maps string to vector. Its keys and values looks like key value "a"-----[1,2,3] "b"-----[8,100] "cde"----[7,10] For each thread, it needs to process ...
5 votes
2 answers
340 views
64bit array operation by C/C++
I have an efficiency critical application, where I need such an array-type data structure A. Its keys are 0, 1, 2,..., and its values are uint64_t distinct values. I need two constant operations: 1. ...
1 vote
1 answer
552 views
Under what circumstances will std::unordered_map behave very slow?
I've done some random tests but I couldn't come to a conclusion. If inserting 1000000 integers in to a map and an unordered_map, the time used by map is 3 times larger. If inserting 1000000 strings ...
0 votes
4 answers
266 views
Is it better to pass by value for moveable types instead of overloading functions? [closed]
I want to reduce copying to a minimum, especially for expensive types/classes. So I could define overloads like this: void SetParams(const std::map<int, std::string> ¶ms) { mParams = ...
-2 votes
1 answer
42 views
How to get the prevalance of each number in an array?
I want to get the information of how many times each number has repeated in array. I was doing something like this: for (int j = 0; j < n; j++){ cin >> x; arr[x]++; } ...