I found that they have one key and multiple values which is unique.
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Override env values defined in container spec
- Converting glm::lookat matrix to quaternion and ba
The latter requires that the values can be ordered (either via
operator<
or a comparison-function), the former does not.The multimap stores pairs of (key, value) where both key and value can appear several times.
The
map<key, set<value>>
will only store each value once for a specific key. To do that, it will have to be able to compare the values, not just the keys.It depends on your application if the values that compare equal are equivalent, or if you wish to store them separately anyway. Perhaps they contain fields that are different but do not take part in the comparison for the set.
Because
map
containers do not allow for duplicate key values, the insertion operation checks for each element inserted whether another element exists already in the container with the same key value if so, the element is not inserted and its mapped value is not changed in any way.on the other hand
can insert any number of items with the same key.
http://www.cplusplus.com/reference/stl/map/
http://www.cplusplus.com/reference/stl/multimap/
A
std::map
is an associative container, that allows you to have a unique key associated with your type value. For example,A
std::multimap
is equal to astd::map
, but your keys are not unique anymore. Therefore you can find a range of items instead of just find one unique item. For example,The
std::set
is like anstd::map
, but it is not storing a key associated to a value. It stores only the key type, and assures you that it is unique within the set.You also have the
std::multiset
, that follows the same pattern.All these containers provide an O(log(n)) access with their find / equal_range.