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 std::multimap, but it's more of a discussion about maps.
Usecases for std::unordered_multiset
3k views Asked by John At
1
There are 1 answers
Related Questions in C++11
- lvalue and rvalue references
- c++ range-for loop over custom class ::begin() expects 1 argument, 0 provided
- Difference between INT_MIN , INT8_MIN , INT16_MIN. For MAX too
- I am getting segmentation failt while assigning the resourcemanager instance
- Prevent reordering of prefetch instruction in c++
- How to Use libcurl to Check HTTP/S Proxy?
- Why we use `class` when there's `struct` in C++?
- Memory Management in C++: Differences in allocating shared_ptr using new vs make_shared
- Does C++ range-based `for` make copies?
- Is the behaviour is determined when initliasing the inner class's static member variable's value equal to the outer class's static member variable?
- Question about initialization. The output must be zeros with C++11 and afterwards?
- How to replace non-standard "for each" received from Visual C++ users
- G ++ can not pass the parameters in using the C ++ 11 process library under Windows?
- Why the Variadic Constructor with std::is_constructible Fails to Handle Initializer List Initialization?
- Class Object Error 'Undefined Reference For'
Related Questions in STL
- Why my code is working on everything except one instance?
- Why does the map size change?
- C++ ordered map optimized with index access
- Circular extention to std::array
- Is there a chance to use a custom std::pmr::polymorphic_allocator to make std::unordered_map’s buckets implemented as arrays?
- STL: Keeping Only Unique String Characters AND Preserving Order
- Importing <filesystem> in gcc
- Are there any iterator invalidation rules for <algorithms> operations?
- Check if Array Is Sorted and Rotated on LeetCode
- std::shared_mutex::unlock_shared() blocks even though there are no active exclusive locks on Windows
- could the type of std::map's key be double or float?
- How to implement an iterator for a two leveled map in C++?
- Why does priority_queue use greater<> for ascending order?
- Scope of C++ references and STL containers
- Implement Non Copyable Non Moveable wrapper for map/vector etc
Related Questions in HASHSET
- HashSet: Why valueType.Equals(Object) is so slow
- Can't print simple HashSet<int[]> elements in java
- Fastest way to check if a GUID of set size has been encountered before
- Get an Array from HashSet in c# with operator [..]
- Dictionary.ContainsKey() vs. large arrays used for lookup, any alternative?
- C# Grabbing subset of table based off a Hashset if Ints
- Code using ArrayList and HashSet in Java i too slow
- Why is my HashSet being serialized incorrectly in ORMLite? It appears to be serialized with the wrong size
- Rust ownership for pushing to a vector whose members are referenced
- Problem with altering property's value of an object that is inside a HashSet in JAVA
- Efficient way to check if a ReadOnlyMemory<char> contains in a Hashset in C#
- Difference between a HashSet in C# and HashSet in Java. Any alternatives
- CSVHelper doesn't store HashSet fields
- Linear probing hash set - efficient way to know if value is already inserted, just not in its hashed index
- Using clear() vs copy() in a hashset
Related Questions in UNORDERED-MULTISET
- Iterator invalidation with unordered_set/unordered_multiset
- Why does the == operator of std::unordered_multiset<T> returns wrong result when T is a pointer type?
- std::unordered_multiset exception iterating bucket
- std::distance goes wrong for unordered map
- I need to create a multiset on Java
- C++ vector of strings into associative vector of ints
- Why multiset keeps separate instances of repeated elements instead of their count?
- what is wrong with this code ? it's not showing any output after executing
- how to end a loop at a particular time in unordered_multiset
- Use of multisets in C++
- Number of distinct elements of std::unordered_multiset
- Generating Subsets of a Multiset in Ascending Order of the Sums of the Elements of the Subset
- Remove only one item from unordered_multiset
- Python inventory of objects
- How to reduce the memory consumption of unordered_multiset?
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
With regards to your question, the most important features of
unordered_multisetcontainers are that:Thus, a typical use-case for
unordered_multisetwould be when you need fast lookup and don't care that the data are unordered:Note that there are other situations where unordered containers cannot or should not be used.
Regarding the uses cases where ordered containers should be prefered to unordered ones, you may want to read this answer. For general guidelines regarding container selection, you may want to read How can I efficiently select a Standard Library container in C++11?.
EDIT
Considering that an unordered multiset and a vector can often do very similar things, isn't it better to always use a vector? Don't vectors automatically outperform unordered multisets?
Reproduced below are the results of a very simple benchmark (full code is provided at the end of this post):
Here are the results obtained for containers of integers :
In the example above, the unordered multiset is slightly better for the Windows benchmark, whereas the sorted vector is slightly better for the CygWin benchmark. For a multi-target development, there is no obvious choice here.
Below are the results of a similar test with containers of strings:
In this example, the unordered multisets outperforms by far the vectors.
The exact figures don't matter much here, as they are specific to the specific conditions (hardware, OS, compiler, compiler options and so on) where these benchmarks were performed. What matters is that vectors sometimes outperform unordered multisets, but sometimes they don't. The only way to be sure whether unordered multisets or vectors should be used for a given application is to benchmark as realistically as feasible.
Below is included the code for the integer container benchmark. As it was developed on the fly, all corrections and improvements are welcome!