CopperSpice API
1.9.2
|
The QMultiMap class is a template class which provides a sorted container of keys and values, allows duplicate keys. More...
Classes | |
class | const_iterator |
STL style const iterator for QMultiMap More... | |
class | iterator |
STL style iterator for QMultiMap More... | |
Public Typedefs | |
using | allocator_type = typename std::multimap< Key, Val, C >::allocator_type |
using | const_pointer = const Val * |
using | const_reference = const Val & |
using | const_reverse_iterator = std::reverse_iterator< const_iterator > |
using | difference_type = typename std::multimap< Key, Val, C >::difference_type |
using | key_compare = typename std::multimap< Key, Val, C >::key_compare |
using | key_type = typename std::multimap< Key, Val, C >::key_type |
using | mapped_type = typename std::multimap< Key, Val, C >::mapped_type |
using | pointer = Val * |
using | reference = Val & |
using | reverse_iterator = std::reverse_iterator< iterator > |
using | size_type = typename std::multimap< Key, Val, C >::difference_type |
using | value_type = Val |
Public Methods | |
QMultiMap () = default | |
QMultiMap (C compare) | |
QMultiMap (const QMultiMap< Key, Val, C > &other) = default | |
QMultiMap (const std::multimap< Key, Val, C > &other) | |
template<typename Input_Iterator > | |
QMultiMap (Input_Iterator first, Input_Iterator last, const C &compare=C ()) | |
QMultiMap (QMultiMap< Key, Val, C > &&other) = default | |
QMultiMap (std::initializer_list< std::pair< const Key, Val >> list, const C &compare=C ()) | |
~QMultiMap () = default | |
iterator | begin () |
const_iterator | begin () const |
const_iterator | cbegin () const |
const_iterator | cend () const |
void | clear () |
const_iterator | constBegin () const |
const_iterator | constEnd () const |
const_iterator | constFind (const Key &key) const |
const_iterator | constFind (const Key &key, const Val &value) const |
bool | contains (const Key &key) const |
bool | contains (const Key &key, const Val &value) const |
size_type | count () const |
size_type | count (const Key &key) const |
size_type | count (const Key &key, const Val &value) const |
const_reverse_iterator | crbegin () const |
const_reverse_iterator | crend () const |
bool | empty () const |
iterator | end () |
const_iterator | end () const |
QPair< iterator, iterator > | equal_range (const Key &key) |
QPair< const_iterator, const_iterator > | equal_range (const Key &key) const |
iterator | erase (const_iterator iter) |
iterator | find (const Key &key) |
const_iterator | find (const Key &key) const |
iterator | find (const Key &key, const Val &value) |
const_iterator | find (const Key &key, const Val &value) const |
Val & | first () |
const Val & | first () const |
const Key & | firstKey () const |
iterator | insert (const Key &key, const Val &value) |
iterator | insert (const std::pair< const Key, Val > &data) |
iterator | insert (const_iterator hint, const Key &key, const Val &value) |
iterator | insertMulti (const Key &key, const Val &value) |
iterator | insertMulti (const_iterator hint, const Key &key, const Val &value) |
bool | isEmpty () const |
const Key | key (const Val &value, const Key &defaultKey=Key ()) const |
QList< Key > | keys () const |
QList< Key > | keys (const Val &value) const |
Val & | last () |
const Val & | last () const |
const Key & | lastKey () const |
iterator | lowerBound (const Key &key) |
const_iterator | lowerBound (const Key &key) const |
bool | operator!= (const QMultiMap< Key, Val, C > &other) const |
QMultiMap | operator+ (const QMultiMap &other) const |
QMultiMap & | operator+= (const QMultiMap &other) |
QMultiMap< Key, Val, C > & | operator= (const QMultiMap< Key, Val, C > &other) = default |
QMultiMap< Key, Val, C > & | operator= (QMultiMap< Key, Val, C > &&other) = default |
bool | operator== (const QMultiMap< Key, Val, C > &other) const |
Val & | operator[] (const Key &key) |
const Val | operator[] (const Key &key) const |
reverse_iterator | rbegin () |
const_reverse_iterator | rbegin () const |
size_type | remove (const Key &key) |
size_type | remove (const Key &key, const Val &value) |
reverse_iterator | rend () |
const_reverse_iterator | rend () const |
iterator | replace (const Key &key, const Val &value) |
size_type | size () const |
void | swap (QMultiMap< Key, Val, C > &other) |
Val | take (const Key &key) |
std::multimap< Key, Val, C > | toStdMultiMap () const |
QList< Key > | uniqueKeys () const |
QMultiMap< Key, Val, C > & | unite (const QMultiMap< Key, Val, C > &other) |
iterator | upperBound (const Key &key) |
const_iterator | upperBound (const Key &key) const |
const Val | value (const Key &key) const |
const Val | value (const Key &key, const Val &defaultValue) const |
QList< Val > | values () const |
QList< Val > | values (const Key &key) const |
Related Functions | |
These are not member functions | |
QDataStream & | operator<< (QDataStream &stream, const QMultiMap< Key, Val, C > &map) |
QDataStream & | operator>> (QDataStream &stream, QMultiMap< Key, Val, C > &map) |
The QMultiMap class is a template class which provides a sorted container of keys and values, allowing duplicate keys. This container stores the key and value as a pair.
For an overview and comparison of all containers, refer to the documentation for Container Classes. Refer to the section on Time Complexity for a discussion about which operations will be relatively faster or slower for a given container with a size of n.
Refer to the QMap documentation for more information about the following topics.
The following examples shows how to create and add elements using a duplicate key.
To retrieve all the values for a given key call values(const Key &key) which will return a QList<T>.
The items which have duplicate keys are available from most recently to least recently inserted. A more efficient version of the code shown above is to call find() to retrieve an STL style iterator to the first item with a given key, then continue to iterate while the key remains the same.
The QMultiMap<Key, Val> should be Default Constructible and Copy Constructible to work with all methods of this class. Data types like QObject are not copy constructible and therefore should never be stored in a container. You can however use a pointer to a QObject or any subclass as the type T.
The QMultiMap key type must provide operator<(). QMultiMap uses the comparison operator to sort. Two keys x
and y
are equal if "x is not less than y" and "y is not less than x".
QMultiMap< Key, Val, C >::allocator_type |
Typedef for allocator used by the container.
QMultiMap< Key, Val, C >::const_pointer |
Typedef for const Val *.
QMultiMap< Key, Val, C >::const_reference |
Typedef for const Val &.
QMultiMap< Key, Val, C >::const_reverse_iterator |
Typedef for an STL style const reverse iterator.
QMultiMap< Key, Val, C >::difference_type |
Typedef for integral type used to represent the distance between two elements.
QMultiMap< Key, Val, C >::key_compare |
Typedef for the key lessthan comparison object type.
QMultiMap< Key, Val, C >::key_type |
Typedef for Key.
QMultiMap< Key, Val, C >::mapped_type |
Typedef for Val.
QMultiMap< Key, Val, C >::pointer |
Typedef for Val *.
QMultiMap< Key, Val, C >::reference |
Typedef for Val &.
QMultiMap< Key, Val, C >::reverse_iterator |
Typedef for an STL style reverse iterator.
QMultiMap< Key, Val, C >::size_type |
Typedef for a signed integer of the appropriate size for your platform.
QMultiMap< Key, Val, C >::value_type |
Typedef for Val.
|
default |
Constructs an empty QMultiMap.
|
default |
Copy constructs a new QMultiMap from other.
|
default |
Move constructs a new QMultiMap from other.
|
inline |
Constructs a multimap with a copy of each of the elements in the initializer list.
If the function object compare is passed it will be called when sorting keys in the container. Refer to Overriding Sort Order for more information about this template parameter.
|
inlineexplicit |
Constructs an empty multimap using the function object compare. Refer to Overriding Sort Order for more information about this parameter.
|
inlineexplicit |
Constructs a copy of other.
|
inline |
Constructs a multimap containing copies of the elements between first and last.
If the function object compare is passed it will be called when sorting keys in the container. Refer to Overriding Sort Order for more information about this template parameter.
|
default |
Destroys the multimap.
|
inline |
Returns an STL style iterator pointing to the first item in the multimap.
|
inline |
Returns a const STL style iterator pointing to the first item in the multimap.
|
inline |
Returns a const STL style iterator pointing to the first item in the multimap.
|
inline |
Returns a const STL style iterator pointing to the imaginary item after the last item in the multimap.
|
inline |
Removes all items from the multimap.
|
inline |
Returns a const STL style iterator pointing to the first item in the multimap.
|
inline |
Returns a const STL style iterator pointing to the imaginary item after the last item in the multimap.
|
inline |
Returns an const iterator pointing to the item with key in the multimap. If the multimap contains no item with key this method returns constEnd().
|
inline |
Returns an iterator pointing to the item with key and the given value in the multimap. If the multimap contains no such item the method returns constEnd().
|
inline |
Returns true if the multimap contains an item with given key, otherwise it returns false.
bool QMultiMap< Key, Val, C >::contains | ( | const Key & | key, |
const Val & | value | ||
) | const |
Returns true if the multimap contains an item with the given key and value, otherwise it returns false.
|
inline |
Equivalent to calling size().
|
inline |
Returns the number of items associated with the given key.
QMultiMap< Key, Val, C >::size_type QMultiMap< Key, Val, C >::count | ( | const Key & | key, |
const Val & | value | ||
) | const |
Returns the number of items with the given key and value.
|
inline |
|
inline |
|
inline |
Equivalent to calling isEmpty().
|
inline |
Returns an STL style iterator pointing to the imaginary item after the last item in the multimap.
|
inline |
Returns a const STL style iterator pointing to the imaginary item after the last item in the multimap.
|
inline |
Returns a pair of iterators corresponding to the range of items [first, second) which have the given key. If the range is empty then both iterators will be equal to end().
|
inline |
Returns a pair of iterators corresponding to the range of items [first, second) which have the given key. If the range is empty then both iterators will be equal to end().
|
inline |
Removes the (key, value) pair pointed to by the iterator iter from the multimap and returns an iterator to the next item in the multimap.
This method assumes the iterator is valid and refers to an element in the multimap. It will not check if iter points past the end of the multimap or is equal to the end() iterator.
|
inline |
Returns an iterator pointing to the item with key in the multimap. If the multimap contains no item with key, the method returns end().
|
inline |
This is an overloaded method.
|
inline |
Returns an iterator pointing to the item with key and value in the multimap. If the multimap contains no such item, the method returns end().
If the multimap contains multiple items with key this method returns an iterator that points to the most recently inserted value.
|
inline |
Returns a const iterator pointing to the item with the given key and value in the multimap. If the multimap contains no such item, the method returns end().
If the multimap contains multiple items with the specified key this method returns a const iterator that points to the most recently inserted value.
|
inline |
Returns a reference to the first value in the multimap. This method assumes the multimap is not empty.
|
inline |
Returns a const reference to the first value in the multimap. This method assumes the multimap is not empty.
|
inline |
Returns a const reference to the first key in the multimap. This method assumes the multimap is not empty.
|
inline |
|
inline |
Inserts a new item with key and value from data, which is an std::pair. If there is already an item with the same key in the multimap, this method will create a new item.
This behavior is different from replace() which overwrites the value of an existing item.
|
inline |
Inserts a new item with the given key and value using hint as a suggestion about where to do the insert. If there is already an item with the same key in the multimap, this method will create a new item.
|
inline |
|
inline |
Inserts a new item with the given key and value using hint as a suggestion about where to do the insert. If there is already an item with the same key, a new one will still be added.
|
inline |
Returns true if the multimap contains no items, otherwise it returns false.
const Key QMultiMap< Key, Val, C >::key | ( | const Val & | value, |
const Key & | defaultKey = Key() |
||
) | const |
Returns the first key with value. If the multimap contains no item with value then defaultKey is returned. If no defaultKey was passed it will be value initialized using the data type of Key. Refer to default constructed elements for additional information.
This method can be slow (linear time), because the internal data structure is optimized for fast lookup by key, not by value.
QList< Key > QMultiMap< Key, Val, C >::keys | ( | ) | const |
Returns a list containing all the keys in the multimap in ascending order. To obtain a list of unique keys, where each key from the multimap only occurs once use uniqueKeys(). The order is guaranteed to be the same as returned by values().
Keys which occur multiple times in the multimap (because items were inserted with insertMulti() or unite()) will also occur multiple times in this list.
QList< Key > QMultiMap< Key, Val, C >::keys | ( | const Val & | value | ) | const |
Returns a list containing all the keys associated with the given value in ascending order.
This method can be slow because the internal data structure is optimized for fast lookup by key, not by value. Refer to linear time.
|
inline |
Returns a reference to the last value in the multimap. This method assumes the map is not empty.
|
inline |
Returns a const reference to the last value in the multimap. This method assumes the map is not empty.
|
inline |
Returns a const reference to the last key in the multimap. This method assumes the map is not empty.
|
inline |
Returns an iterator pointing to the first item with key in the multimap. If the multimap contains no item with key then the method returns an iterator to the nearest item with a greater key.
If the multimap contains multiple items with the same key then this method will return an iterator which points to the most recently inserted value. The other values are accessible by incrementing the iterator. For example, the following code iterates over all the items with the same key.
|
inline |
This is an overloaded method.
|
inline |
Returns true if other is not equal to this multimap, otherwise it returns false. Two multimaps are considered equal if they contain the same (key, value) pairs.
This method requires the type T to support operator==()
.
|
inline |
Returns a multimap that contains all the items in this multimap in addition to all the items in other. If a key is common to both multimaps the resulting multimap will contain the key multiple times.
|
inline |
Inserts all the items in the other multimap into this map and returns a reference to this multimap.
|
default |
Copy assigns from other and returns a reference to this object.
|
default |
Move assigns from other and returns a reference to this object.
|
inline |
Returns true if other is equal to this multimap, otherwise it returns false. Two multimaps are considered equal if they contain the same (key, value) pairs.
This method requires the type T to support operator==()
.
Val & QMultiMap< Key, Val, C >::operator[] | ( | const Key & | key | ) |
Returns a reference to the value for the item with the given key. If no item with key is found, a new value initialized object of type Val with the given key is inserted. Refer to default constructed elements for additional information.
|
inline |
|
inline |
This is an overloaded method.
|
inline |
|
inline |
Removes all the items which have the given key. Returns the number of items removed which is usually 1, however this will be 0 if the key is not in the multimap, or greater than 1 if insertMulti() has been used with the key.
QMultiMap< Key, Val, C >::size_type QMultiMap< Key, Val, C >::remove | ( | const Key & | key, |
const Val & | value | ||
) |
Removes all the items which have the given key and value. Returns the number of items removed.
|
inline |
|
inline |
This is an overloaded method.
|
inline |
Inserts a new item with the given key and value. If there is already an item with the key key, that item's value is replaced with value.
If there are multiple items with the key, the most recently inserted item's value is replaced with value.
|
inline |
|
inline |
Swaps multimap other with this multimap. This operation is very fast and never fails.
|
inline |
Removes the item with the given key from the multimap and returns the value. If there are multiple items for key in the multimap, the most recently inserted one is removed and returned. If you do not use the return value calling remove() will be more efficient. If the multimap contains no item with key, then a value initialized object of type Val is returned. Refer to default constructed elements for additional information.
This method can not be called if the return type for Val is a "move only" type. For move only data types the following steps can be used to retrieve the value and then erase the element. Call operator[] or find() and then access the data by calling iter.value(). Call erase() to remove the element.
std::multimap< Key, Val, C > QMultiMap< Key, Val, C >::toStdMultiMap | ( | ) | const |
Returns an STL multimap equivalent to this QMultiMap.
QList< Key > QMultiMap< Key, Val, C >::uniqueKeys | ( | ) | const |
Returns a list containing all the keys in the multimap in ascending order. Keys that occur multiple times in the multimap (because items were inserted with insertMulti(), or unite() was used) occur only once in the returned list.
|
inline |
Inserts all the items in the other multimap into this multimap. If a key is common to both multimaps, the resulting map will contain the key multiple times.
|
inline |
Returns an iterator pointing to the item which immediately follows the last item with key in the multimap. If the map contains no item with key, the method returns an iterator to the nearest item with a greater key.
|
inline |
This is an overloaded method.
const Val QMultiMap< Key, Val, C >::value | ( | const Key & | key | ) | const |
Returns the value associated with the given key. If there are multiple items for key in the multimap, the value of the most recently inserted one is returned. If no item with key is found then a value initialized object is returned. Refer to default constructed elements for additional information.
This method can not be called if the return type for Val is a "move only" type. For move only data types the following steps can be used to retrieve the value. Call operator[] or find() and then access the data by calling iter.value().
const Val QMultiMap< Key, Val, C >::value | ( | const Key & | key, |
const Val & | defaultValue | ||
) | const |
Returns the value associated with the specified key. If the multimap contains no element with the given key then defaultValue is returned. If no defaultValue was passed it will be value initialized using the data type of Val. Refer to default constructed elements for additional information.
This method can not be called if the return type for Val is a "move only" type. For move only data types the following steps can be used to retrieve the value. Call find() and check if the key was found.
QList< Val > QMultiMap< Key, Val, C >::values | ( | ) | const |
QList< Val > QMultiMap< Key, Val, C >::values | ( | const Key & | key | ) | const |
Returns a list containing all the values associated with key, from the most recently inserted to the least recently inserted one.
|
related |
Writes the given map to the stream. Returns a reference to the stream. This function requires the key and value types to implement operator<<()
.
Refer to Serializing Data Types for additional information.
|
related |
Reads from the stream into the given map. Returns a reference to the stream. This function requires the key and value types to implement operator>>()
.
Refer to Serializing Data Types for additional information.