Questions tagged [unordered-multiset]

Use this tag for questions related to the unordered multiset, either it has to do with std::unordered_multiset of C++11, or with a custom implementation.

Currently all the questions with are related to std::unordered_multiset, a container introduced in C++11. However, users attempting to build their own custom implementation of that container, are also welcome to use his tag.

Quoting cplusplus:

Unordered multisets are containers that store elements in no particular order, allowing fast retrieval of individual elements based on their value, much like unordered_set containers, but allowing different elements to have equivalent values.


cppreference.com also has a dedicated entry to this container.

20 questions
10
votes
2 answers

What are some uses of local iterator for STL unordered containers?

In §23.2.7 Unordered associative containers [unord.req] of the C++ standard table 91 describes the additional requirements a STL unordered associative container must meet. In this table the standard dictates that the STL unordered containers (i.e.,…
101010
  • 41,839
  • 11
  • 94
  • 168
6
votes
1 answer

Usecases for std::unordered_multiset

I'd like to know why one would ever use std::unordered_multiset. My guess is it has something to do with invalidations or non-invalidations of iterators after insert/erase, but maybe its something deeper? Very similar question is here: Use cases of…
John
  • 1,709
  • 1
  • 24
  • 27
6
votes
1 answer

Complexity of std::unordered_multiset insert

Why is the worst case complexity of std::unordered_multiset insert is linear? I understand why is that the case for std::unordered_set (you have to check that inserted value is not in the set) but for multiset I don't get it. Am I missing something…
3
votes
1 answer

Remove only one item from unordered_multiset

I want to erase a specific element from std::unordered_multiset, but when I try with erase function, it eliminates all the items, no matter how many they are. For example: std::unordered_multiset
Eduard Rostomyan
  • 7,050
  • 2
  • 37
  • 76
2
votes
2 answers

Why multiset keeps separate instances of repeated elements instead of their count?

I recently found out that multiset implementation in STL actually keeps different copies of the same repeated elements in the tree. My expectation before was for it to internally use a map and just keep the count of the repeated…
Scarlet
  • 271
  • 2
  • 12
2
votes
3 answers

Python inventory of objects

I want to be able to perform "math" operations on object instances. lets assume I have a Fruit class and then additional Orange(Fruit) and Apple(Fruit) classes. Apple's have a color attribute and the class is aware of the face that "red apples" are…
epeleg
  • 10,347
  • 17
  • 101
  • 151
1
vote
2 answers

Why does the == operator of std::unordered_multiset returns wrong result when T is a pointer type?

Is this a bug, or am I doing something wrong? I already tried providing hashing and equality functors for the pointer type, but it doesn't seem to work. I even tried creating my own miniature template container just to test the functors. Hashing…
1
vote
2 answers

C++ vector of strings into associative vector of ints

Im having trouble to convert a string vector with size of ~ 1.0000.0000 elements to an associative vector with integers. Input: std::vector s {"a","b","a","a","c","d","a"}; Desired output: std::vector i {0,1,0,0,2,3,0}; I was…
schlumpel
  • 174
  • 1
  • 8
1
vote
2 answers

how to end a loop at a particular time in unordered_multiset

Good morning, I am trying for a loop when a particular condition is met in an unordered_multiset with the end operation. But it does not work and I get a Segmentation fault in the next iteration of the loop. Code: std::unordered_multiset
juan
  • 17
  • 5
1
vote
1 answer

Use of multisets in C++

I understand the usage on sets in C++, but why do multisets exist? What are some real world applications where multisets are useful? This argument can extended for unordered multisets as well, what differentiates then from using a vector and what…
Ayush
  • 91
  • 1
  • 10
1
vote
2 answers

Why unordered_multiset works bad for many equal keys

I have this piece of code: unordered_multiset t; for (int i = 0; i < 1000000; i++) { if (i % 10000 == 0) cout << i << endl; t.insert(10); } So it just puts a lot of equal elements in an unordered_multiset. But I found out that…
Nikita
  • 837
  • 1
  • 12
  • 23
1
vote
3 answers

Count in Multiset

I have been using the C++ STL for a while but never really got around to using multisets (or multimaps). I have a question based on counting the number of elements with the same key. For eg. Here is an unordered_multiset {0, 2, 5, 1, 1, 2, 7, 5} If…
ibp73
  • 650
  • 1
  • 6
  • 16
1
vote
2 answers

Does std::unordered_multiset::find function return the first inserted element between two values with same hash value

Saying we have std::unordered_multiset with two values mapping the same hash value, is there any guarantees by the c++ standard that a find will return the first inserted element ?
Guillaume Paris
  • 10,303
  • 14
  • 70
  • 145
0
votes
1 answer

std::unordered_multiset exception iterating bucket

My test case is the one shown below: std::size_t t(const int &i) { return i | 0b01010101010101010101010101010101; } int main() { std::unordered_multiset um(100, t); um.insert(9872934); um.insert(9024582); …
PaperBirdMaster
  • 12,806
  • 9
  • 48
  • 94
0
votes
0 answers

std::distance goes wrong for unordered map

What's wrong with std::distacne in this code snippet? As far as I know, for std::map or std::vector, it's ok to invoke std::distance. But for this code snippet, the program will break down if std::distance is called. // constructing…
John
  • 2,963
  • 11
  • 33
1
2