Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
119 views

I'm experimenting with std::unordered_map performance in C++20 and noticed that when I insert a large number of elements, the container sometimes rehashes multiple times even though I called reserve() ...
Kenz Bilal's user avatar
1 vote
1 answer
140 views

In the code below I'm defining a map and a multimap. Then I'm defining four iterators assigning them values from these containers: std::map<int, double> m; std::multimap<int, double> mm; ...
Dmitry Kuzminov's user avatar
0 votes
1 answer
111 views

Here is a small piece of code: class myClass { public: void myMethod() const { for (const auto& entity : myList) { auto iter = myMap.find(&entity); } } private: std::list&...
Romain's user avatar
  • 47
1 vote
2 answers
218 views

Say I have a C++ class containing an id: class MyData { std::string _id; std::vector<int> _stuff; public: const std::string& id() { return _id; } MyData(std::string id) : ...
Mark Charsley's user avatar
0 votes
1 answer
233 views

From what I know, unordered_map (hash table) should be faster than map (red-black tree). But when I tested them in Visual Studio, unordered_map was faster for both insertion and lookup. However, when ...
ValExi's user avatar
  • 157
0 votes
0 answers
110 views

I have tested the following code and the run crashed at when the map does ~_Hashtable() and clear(). This case is simplified from my project. And I do need to use thread_local to describe map. I want ...
dioszz's user avatar
  • 1
1 vote
1 answer
75 views

Is it possible to hash boost::dynamic_bitset as keys in unordered map directly without converting it to string? For instance, declare a hashmap as std::unordered_map<boost::dynamic_bitset<>, ...
monotonic's user avatar
  • 650
1 vote
1 answer
153 views

A while back I ported some of the C++ stdlib containers to environment where stdlib was not available. While iterators for contiguous and node-based containers were easy, I was stumped how to ...
Dominik Kaszewski's user avatar
2 votes
2 answers
230 views

I realize that std::unordered_map doesn't make strong promises about its ordering. But it has to make SOME promises to make basic functionalitiy work. For example, see the example in https://en....
lewis's user avatar
  • 1,333
2 votes
0 answers
127 views

I'm looking at the definition of std::unordered_map<Key,T,Hash,KeyEqual,Allocator>::insert_or_assign in cppreference, and in all signatures, there is template < class M >, standing for ...
Hayk's user avatar
  • 69
3 votes
2 answers
160 views

Hi I am working with std::unordered map. I am dealing with a lot of inserts. The count of inserts is known ahead. I thought to optimize the memory by using the reserve methodand assuming it pre-...
Boris's user avatar
  • 1,489
3 votes
3 answers
260 views

Boost unordered_flat_map is pretty good, it's way faster than std::unordered_map. I'm trying to use it with heterogenous key types: boost::unordered::unordered_flat_map<std::string, int> my_map; ...
Zebrafish's user avatar
  • 16.3k
0 votes
3 answers
204 views

I was cloning a graph (deep copy) and the only problem in my code is in the BFS() function inside the if statement, when I'm updating the visited hashmap, it's not updating. Node* cloneGraph(Node* ...
BITE004 Mir Aatif's user avatar
0 votes
1 answer
328 views

I am trying to use std::unordered_map with std::wstring and std::pair<int, int> as value, but I want to compare keys in lower letters. I am using C++20 But I am unable to compile this code. #...
Sahib Yar's user avatar
  • 1,046
1 vote
0 answers
162 views

Minimal Example code: int main(){ std::unordered_map<int,int> data = { {1,2}, {2,3}, {3,4} }; data[4] = 5; } I'm breaking on the last line (data[4] =5;). ...
gabriel__'s user avatar
1 vote
1 answer
111 views

I am new to allocators. I am experimenting with a custom allocator used to allocate std::unordered_map and string: #include <string> #include <string_view> #include <unordered_map> ...
user2961927's user avatar
  • 1,790
-1 votes
1 answer
85 views

AFAIU (maybe I am wrong), unordered_set/unordered_map use underlying array or vector for buckets, and in each bucket there is a list of keys (or key-value). So when we want more buckets, larger array ...
Andrey Rubliov's user avatar
0 votes
3 answers
226 views

This is a simple program consisting of adding an element into the std::unordered_map. But before it's added, first check if the key already exists, if it does then don't add it. My problem is that ...
tadm123's user avatar
  • 8,899
1 vote
1 answer
88 views

I'm wondering why do I have this error compiling the following example code: #include <unordered_map> #include <memory> class OneClass { }; using TestUnorderedMap = std::unordered_map&...
rbarreiros's user avatar
0 votes
1 answer
122 views

I am currently writing a console program in C++ that builds a network/graph of nodes and arcs that connect to eachother using unordered maps. The purpose of the application is to demonstrate the "...
53R3N1TY's user avatar
0 votes
1 answer
65 views

I have a wrapper class around uint32_t: class IPv4 { uint32_t octets_; public: operator uint32_t() {return octets;} }; Also I have a structure inherited from IPv4 class: struct routerID : ...
razenkovv's user avatar
-2 votes
1 answer
236 views

Consider the following: In C++, the std::unordered_map uses a hash function in the insertion process to determine where the new inserted element will be located. However, the std::map does not use a ...
user avatar
0 votes
2 answers
196 views

I am trying to understand how STL unordered set/map (i.e. hash maps) work. I understood that initial hash table size (i.e. number of buckets) is set to 8 and when more elements are added to the set/...
Andrey Rubliov's user avatar
3 votes
2 answers
93 views

Code #include <iostream> #include <unordered_map> #include <utility> using namespace std; struct Foo { Foo(const int value) : val(value) { cout << "Foo(int), ...
Rebased's user avatar
  • 51
0 votes
0 answers
94 views

While liked-list buckets implementation in std::unordered_map works well when one needs to add/remove elements from the container, it still could be speed up significantly if “stable” or “read-only” ...
Damir Tenishev's user avatar
0 votes
1 answer
135 views

I'm working on a C++ project where I've defined a custom class to use as the key in an unordered_map. To do this, I overrode the == operator and provided a custom hash function. The following is a ...
maplemaple's user avatar
  • 1,805
15 votes
1 answer
425 views

I know about this question, but mine is a bit different. Why does rehash have quadratic complexity, but operator [] (which can call rehash) has linear complexity in worst case? Sorry, but I don't have ...
bash mac's user avatar
  • 151
0 votes
0 answers
76 views

During a loop on an std::unordered_map I need in some cases to add a new element to the map: for (auto &element : map) { if (condition) { map.insert(newElement); } // Do something with ...
Nicola Mori's user avatar
0 votes
0 answers
110 views

The program I am trying to make takes an "n * n" square matrix grid of size "n * n" with values in the range [1,n²]. Each integer appears exactly once except a number 'a' which ...
Andy 's user avatar
  • 11
0 votes
1 answer
299 views

I'm trying to create a set of pair<int, string> in C++ and sort it efficiently using a custom comparator. My requirements are: Primary sort: Descending order based on the integer element of the ...
yousef sayed's user avatar
-1 votes
1 answer
162 views

can i declare an unordered_map with pair<int, int> as key without providing a custom hash function, as long as the compiler and standard library support C++11 or later.? just like this: #include ...
Baylor's user avatar
  • 11
2 votes
2 answers
404 views

I just found a bug in my code that depends on the order the elements are stored in an unordered_map. Ok not a big deal, I'm going to fix it. My question is only out of curiosity to understand ...
JRR's user avatar
  • 3,293
4 votes
1 answer
176 views

I have integer keys which have to be associated to std::vector<T>, with T an iterator-like object (you can safely assume each element of the vector is a pointer). The obvious candidate from the ...
FEGuy's user avatar
  • 97
0 votes
1 answer
251 views

I'm trying to populate an unordered_map [class member] in a method called in the Constructor initializer list. I get a runtime exception at map[0] = 1 which seems to be due to the member not being ...
J. Moutray's user avatar
2 votes
0 answers
103 views

Introduction I recently upgraded the gcc version of a project from 7.5 to 11.4. After the upgrade, I found some exceptions at runtime. After tracing, it was found that an exception occurred when ...
Anoyer's user avatar
  • 21
0 votes
0 answers
113 views

I have std::unordered_map<char, Argument&> and it works fine, but when I try to declare std::stack<Argument&>, I'm getting the following error: In template: 'allocate' declared as ...
awakair's user avatar
0 votes
1 answer
109 views

I want to construct a graph whose Vertex is defined as follows: struct Vertex { string key; // key of the vertex. vector<string> adj; // keys of adjacent vertices. ...
Der Fänger im Roggen's user avatar
1 vote
1 answer
89 views

The std::unordered_map has hash-value for each key. What is the way to obtain those hash values? What for? To evaluate relevance of a hash function to the data set. I could just generate hashes from ...
Igor Polk's user avatar
-1 votes
3 answers
179 views

We have just found a bug in our code, that goes something like this: class foo { unordered_map<int,string> m_someMap; public: void stuff() { unordered_map<int, string> ...
Ivan Krivyakov's user avatar
1 vote
3 answers
798 views

This was a source of confusion for me, but std::unordered_map::try_emplace takes the key and variable arguments for the constructor of the value(mapped) type, however ::emplace is supposed to take an ...
Zebrafish's user avatar
  • 16.3k
4 votes
1 answer
267 views

In the following code, I have defined template arguments Hash and KeyEqual for unordered_map. I expect the output to be 1 1 1 1 but it is actually 1 1 0 1. Why does this happen? Is it because std::...
Trams's user avatar
  • 421
1 vote
1 answer
197 views

I have a complex multi-layered dictionary in Python, and I want to know how to "translate" such thing to C++. I am just a beginner in C++ so I use C++20 standard, my IDE is Visual Studio ...
Ξένη Γήινος's user avatar
-1 votes
1 answer
179 views

I'm using std::unordered_map in my own class. The code is like the following: #include <iostream> #include <unordered_map> template<class T> class MSet { public: std::...
Trams's user avatar
  • 421
0 votes
2 answers
875 views

I am trying to use my custom allocator for a std::unordered_map. The allocator already works for my own objects and also for std::vector, but when I try to use it in the same way for a std::...
Jager's user avatar
  • 5
-1 votes
1 answer
91 views

Say we have something like this: template<typename T> class SparseMatrix { // Where the first (K,V) is (row_idx, columns) and the second is (col_idx, numeric type) using Entries = std::...
Ders's user avatar
  • 13
0 votes
1 answer
862 views

I am trying to define two unordered maps at global level, I define them with loops and I don't want to put the loops to main(). More specifically I am trying to define a base-36 alphabet, I use Arabic ...
Ξένη Γήινος's user avatar
0 votes
0 answers
37 views

I have defined a unordered map object as follows. Here ndmInst is a user defined class. slmEndpointsTimingInfo is also a user defined class. I have also shown how I am inserting it into it and the ...
chhatna's user avatar
1 vote
2 answers
104 views

I am setting up an unordered_map, in which the key is an enum of Direction defined as: enum Direction : uint16_t { North = 1 << 0, East = 1 << 2, South = 1 << 3, West ...
Ian's user avatar
  • 73
4 votes
1 answer
595 views

Say I have std::unordered_map<int, Foo> myMap;. If I call myMap.erase(1);, will Foo's destructor always be called immediately? Or is the standard library allowed to hang on that instance of Foo ...
gregschlom's user avatar
  • 4,995
0 votes
1 answer
256 views

Problem Statement You are given a list of a repeated set of integers. Your task for the problem is to return a list of the given elements in decreasing sorted order of their frequency of repetition in ...
vss_suba's user avatar

1
2 3 4 5
33