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 best solutions below
Related Questions in C++11
- C++ using std::vector across boundaries
- Using QPointer and QObject::connect with C++11
- Using std::vector<> and std::shared_ptr<> should cause error
- invoking function for each variadic template arguments and passing the result as constructor arguments
- Different behavior of async with Visual Studio 2013(Windows8.1) and GCC 4.9(Ubuntu14.10)
- Whether to use T const& or T&&
- C++ IRC Bot Buffer Error
- Downcast from a container of Base* to Derived* without explicit conversion
- Assigning values in a vector in non-sequential order
- Can I use C++11 list-initializer syntax for vectors with variables?
- is it fine to use auto keyword in function parameter?
- Variadic template method and std::function - compilation error
- Clustering on Graph (using Boost Graph Library)
- libc++ difference between vector::insert overloads
- Cannot convert argument1 to const char
Related Questions in STL
- C++ using std::vector across boundaries
- Downcast from a container of Base* to Derived* without explicit conversion
- C++ Custom std::map<> key class causing memory violation
- How to get rid of the ".\r\n" characters appended to the error message from FormatMessageA?
- What is the equivalent of boost::system::error_code with GetLastError in C++ Standard Library?
- How to insert data into map where one parameter is an object?
- C++11 template instance wrapping vector makes error
- No viable conversion std::weak_ptr to std::shared_ptr for method call
- syntax: doing binary_search (STL) for sorted vector of pointers to struct
- Linker error using VS 2015 RC, can't find symbol related to std::codecvt
- Pass vector of char vectors to char**
- Android NDK / Exceptions?
- How to insert data into nested map in c++?
- Which STL container(s)/algorithm(s) could I use to solve this?
- Is there a way to iterate over at most N elements using range-based for loop?
Related Questions in HASHSET
- Does java.util.HashSet not Adhere to its Specification?
- Optimizing list performance in C#
- Storing data in sorted manner in a HashSet
- Java: HashSet multiple types
- How to test collections in Junit (Java)
- Initialize method from HashSet
- Removing HashSet with Object
- Finding matching objects in Java
- how to not sort a HashSet values and allow duplicate?
- Why objects are not same added to hashset with same value, even hashCode and equals are overriden
- Calling a method from another class with the getMethod gives an error
- Viewbag , Printing data from hashset
- java: HashSet to show error message on inputing duplicate Integer values
- How Hashset avoids duplicates
- Implementing custom object for HashSet
Related Questions in UNORDERED-MULTISET
- Iterator invalidation with unordered_set/unordered_multiset
- std::unordered_multiset exception iterating bucket
- Generating Subsets of a Multiset in Ascending Order of the Sums of the Elements of the Subset
- Why does the == operator of std::unordered_multiset<T> returns wrong result when T is a pointer type?
- How to reduce the memory consumption of unordered_multiset?
- What are some uses of local iterator for STL unordered containers?
- Use of multisets in C++
- Remove only one item from unordered_multiset
- Why multiset keeps separate instances of repeated elements instead of their count?
- Number of distinct elements of std::unordered_multiset
- how to end a loop at a particular time in unordered_multiset
- what is wrong with this code ? it's not showing any output after executing
- Python inventory of objects
- Usecases for std::unordered_multiset
- std::distance goes wrong for unordered map
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)
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?
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!