CopperSpice API  1.9.2
QMultiHash< Key, Val, Hash, KeyEqual > Class Template Reference

Template class which provides an unordered container of keys and values, allows duplicate keys. More...

Classes

class  const_iterator
 STL style const iterator for QMultiHash More...
 
class  iterator
 STL style non-const iterator for QMultiHash More...
 

Public Typedefs

using const_pointer = const Val *
 
using const_reference = const Val &
 
using difference_type = typename std::unordered_multimap< Key, Val, Hash, KeyEqual >::difference_type
 
using hasher = typename std::unordered_multimap< Key, Val, Hash, KeyEqual >::hasher
 
using key_equal = typename std::unordered_multimap< Key, Val, Hash, KeyEqual >::key_equal
 
using key_type = typename std::unordered_multimap< Key, Val, Hash, KeyEqual >::key_type
 
using mapped_type = typename std::unordered_multimap< Key, Val, Hash, KeyEqual >::mapped_type
 
using pointer = Val *
 
using reference = Val &
 
using size_type = typename std::unordered_multimap< Key, Val, Hash, KeyEqual >::difference_type
 
using value_type = Val
 

Public Methods

 QMultiHash () = default
 
 QMultiHash (const Hash &hash, const KeyEqual &key=KeyEqual ())
 
 QMultiHash (const QMultiHash< Key, Val, Hash, KeyEqual > &other) = default
 
 QMultiHash (const std::unordered_multimap< Key, Val, Hash, KeyEqual > &other)
 
template<typename Input_Iterator >
 QMultiHash (Input_Iterator first, Input_Iterator last, const Hash &hash=Hash (), const KeyEqual &key=KeyEqual ())
 
 QMultiHash (QMultiHash< Key, Val, Hash, KeyEqual > &&other) = default
 
 QMultiHash (std::initializer_list< std::pair< const Key, Val >> list, const Hash &hash=Hash (), const KeyEqual &key=KeyEqual ())
 
 QMultiHash (std::unordered_multimap< Key, Val, Hash, KeyEqual > &&other)
 
 ~QMultiHash () = default
 
iterator begin ()
 
const_iterator begin () const
 
size_type capacity () 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
 
bool empty () const
 
iterator end ()
 
const_iterator end () const
 
QPair< iterator, iteratorequal_range (const Key &key)
 
QPair< const_iterator, const_iteratorequal_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
 
iterator insert (const Key &key, const Val &value)
 
iterator insert (const std::pair< const Key, Val > &data)
 
iterator insertMulti (const Key &key, const Val &value)
 
bool isEmpty () const
 
const Key key (const Val &value) const
 
const Key key (const Val &value, const Key &defaultKey) const
 
QList< Key > keys () const
 
QList< Key > keys (const Val &value) const
 
bool operator!= (const QMultiHash< Key, Val, Hash, KeyEqual > &other) const
 
QMultiHash operator+ (const QMultiHash &other) const
 
QMultiHash & operator+= (const QMultiHash &other)
 
QMultiHash< Key, Val, Hash, KeyEqual > & operator= (const QMultiHash< Key, Val, Hash, KeyEqual > &other) = default
 
QMultiHash< Key, Val, Hash, KeyEqual > & operator= (QMultiHash< Key, Val, Hash, KeyEqual > &&other) = default
 
bool operator== (const QMultiHash< Key, Val, Hash, KeyEqual > &other) const
 
Val & operator[] (const Key &key)
 
const Val operator[] (const Key &key) const
 
size_type remove (const Key &key)
 
size_type remove (const Key &key, const Val &value)
 
iterator replace (const Key &key, const Val &value)
 
void reserve (size_type size)
 
size_type size () const
 
void squeeze ()
 
void swap (QMultiHash< Key, Val, Hash, KeyEqual > &other)
 
Val take (const Key &key)
 
QList< Key > uniqueKeys () const
 
QMultiHash< Key, Val, Hash, KeyEqual > & unite (const QMultiHash< Key, Val, Hash, KeyEqual > &other)
 
Val value (const Key &key) 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

QDataStreamoperator<< (QDataStream &stream, const QMultiHash< Key, Val, Hash, KeyEqual > &hash)
 
QDataStreamoperator>> (QDataStream &stream, QMultiHash< Key, Val, Hash, KeyEqual > &hash)
 

Detailed Description

template<typename Key, typename Val, typename Hash, typename KeyEqual>
class QMultiHash< Key, Val, Hash, KeyEqual >

The QMultiHash class is a template class which provides an unordered 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.

Basic Operations

The following examples shows how to create and add elements using a duplicate key.

hash1.insert("plenty", 100);
hash1.insert("plenty", 2000); // hash1.size() == 2
hash2.insert("plenty", 5000); // hash2.size() == 1
hash3 = hash1 + hash2; // hash3.size() == 3

To retrieve all the values for a given key use values(const Key &key) which will return a QList<T>.

QList<int> values = hash.values("plenty");
for (int i = 0; i < values.size(); ++i) {
cout << values.at(i) << endl;
}

The items which share the same key are guaranteed to be adjacent but unordered within the hash. 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.

while (iter != hash.end() && iter.key() == "plenty") {
cout << iter.value() << endl;
++iter;
}

Constraints on type T

The QMultiHash<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 QMultiHash Key type support operator==().

There must also be a global qHash() function which returns a hash value for an argument of the key's type. The following is a list of data types which can serve as keys in a QMultiHash. The <QHash> header file defines qHash() functions which compute an hash values for the following data types.

See also
QHash

Member Typedef Documentation

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::const_pointer

Typedef for const Val *.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::const_reference

Typedef for const Val &.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::difference_type

Typedef for integral type used to represent the distance between two elements.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::hasher

Typedef for the multihash object type.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::key_equal

Typedef for the key equality comparison object type.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::key_type

Typedef for Key.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::mapped_type

Typedef for Val.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::pointer

Typedef for Val *.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::reference

Typedef for Val &.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::size_type

Typedef for a signed integer of the appropriate size for your platform.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::value_type

Typedef for Val.

Constructor & Destructor Documentation

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::QMultiHash ( )
default

Constructs an empty QMultiHash.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::QMultiHash ( const QMultiHash< Key, Val, Hash, KeyEqual > &  other)
default

Copy constructs a new QMultiHash from other.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::QMultiHash ( QMultiHash< Key, Val, Hash, KeyEqual > &&  other)
default

Move constructs a new QMultiHash from other.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::QMultiHash ( std::initializer_list< std::pair< const Key, Val >>  list,
const Hash &  hash = Hash(),
const KeyEqual &  key = KeyEqual() 
)
inline

Constructs a QMultiHash with a copy of each of the elements in the initializer list.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::QMultiHash ( const Hash &  hash,
const KeyEqual &  key = KeyEqual() 
)
inlineexplicit

Constructs a QMultiHash using the given hash and key.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::QMultiHash ( const std::unordered_multimap< Key, Val, Hash, KeyEqual > &  other)
inlineexplicit

Constructs a new QMultiHash which contains copies of the items in other.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::QMultiHash ( std::unordered_multimap< Key, Val, Hash, KeyEqual > &&  other)
inlineexplicit

Move constructs a new QMultiHash using the items in other.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
template<typename Input_Iterator >
QMultiHash< Key, Val, Hash, KeyEqual >::QMultiHash ( Input_Iterator  first,
Input_Iterator  last,
const Hash &  hash = Hash(),
const KeyEqual &  key = KeyEqual() 
)
inline

Constructs a QMultiHash containing copies of the items between the first and last iterators.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::~QMultiHash ( )
default

Destroys the QMultiHash.

Method Documentation

template<typename Key , typename Val , typename Hash , typename KeyEqual >
iterator QMultiHash< Key, Val, Hash, KeyEqual >::begin ( )
inline

Returns a STL-style iterator pointing to the first item in the multihash.

See also
constBegin(), end()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
const_iterator QMultiHash< Key, Val, Hash, KeyEqual >::begin ( ) const
inline

Returns a const STL-style iterator pointing to the first item in the multihash.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
size_type QMultiHash< Key, Val, Hash, KeyEqual >::capacity ( ) const
inline

Returns the number of buckets in the QHash's internal hash table.

The purpose of this method is to provide a means of fine tuning QHash's memory usage. In general, you will rarely ever need to call this method. If you want to know how many items are in the hash call size().

See also
reserve(), squeeze()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
const_iterator QMultiHash< Key, Val, Hash, KeyEqual >::cbegin ( ) const
inline

Returns a const STL style iterator pointing to the first item in the multihash.

See also
begin(), cend()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
const_iterator QMultiHash< Key, Val, Hash, KeyEqual >::cend ( ) const
inline

Returns a const STL style iterator pointing to the imaginary item after the last item in the multihash.

See also
cbegin(), end()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
void QMultiHash< Key, Val, Hash, KeyEqual >::clear ( )
inline

Removes all items in the current QMultiHash.

See also
remove()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
const_iterator QMultiHash< Key, Val, Hash, KeyEqual >::constBegin ( ) const
inline

Returns a const STL style iterator pointing to the first item in the multihash.

See also
begin(), constEnd()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
const_iterator QMultiHash< Key, Val, Hash, KeyEqual >::constEnd ( ) const
inline

Returns a const STL style iterator pointing to the imaginary item after the last item in the multihash.

See also
constBegin(), end()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
const_iterator QMultiHash< Key, Val, Hash, KeyEqual >::constFind ( const Key &  key) const
inline

Returns a const iterator pointing to the item with the given key. If the multihash contains no matching items, returns constEnd().

See also
find()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::const_iterator QMultiHash< Key, Val, Hash, KeyEqual >::constFind ( const Key &  key,
const Val &  value 
) const
inline

Returns a const iterator pointing to the item with the given key and the value. If the multihash contains no matching items, returns constEnd().

See also
constFind()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
bool QMultiHash< Key, Val, Hash, KeyEqual >::contains ( const Key &  key) const
inline

Returns true if the multihash contains an item with the given key, otherwise returns false.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
bool QMultiHash< Key, Val, Hash, KeyEqual >::contains ( const Key &  key,
const Val &  value 
) const
inline

Returns true if the multihash contains an item with the given key and value, otherwise returns false.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
size_type QMultiHash< Key, Val, Hash, KeyEqual >::count ( ) const
inline

Returns the number of items in this multihash. Equivalent to calling size().

template<typename Key , typename Val , typename Hash , typename KeyEqual >
size_type QMultiHash< Key, Val, Hash, KeyEqual >::count ( const Key &  key) const
inline

Returns the number of items which have the given key.

See also
contains(), insertMulti()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::size_type QMultiHash< Key, Val, Hash, KeyEqual >::count ( const Key &  key,
const Val &  value 
) const

Returns the number of items which have the given key and value.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
bool QMultiHash< Key, Val, Hash, KeyEqual >::empty ( ) const
inline

Equivalent to calling isEmpty().

template<typename Key , typename Val , typename Hash , typename KeyEqual >
iterator QMultiHash< Key, Val, Hash, KeyEqual >::end ( )
inline

Returns an STL-style iterator pointing to the imaginary item after the last item in the multihash.

See also
begin(), constEnd()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
const_iterator QMultiHash< Key, Val, Hash, KeyEqual >::end ( ) const
inline

Returns a const STL-style iterator pointing to the imaginary item after the last item in the multihash.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QPair< iterator, iterator > QMultiHash< Key, Val, Hash, KeyEqual >::equal_range ( const Key &  key)
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().

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QPair< const_iterator, const_iterator > QMultiHash< Key, Val, Hash, KeyEqual >::equal_range ( const Key &  key) const
inline

Returns a pair of const 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().

template<typename Key , typename Val , typename Hash , typename KeyEqual >
iterator QMultiHash< Key, Val, Hash, KeyEqual >::erase ( const_iterator  iter)
inline

Removes the (key, value) pair pointed to by the iterator iter from the multihash and returns an iterator to the next item in the multihash.

This method assumes the iterator is valid and refers to an element in the multihash. It will not check if iter points past the end or is equal to the end() iterator. This method does not cause QMultiHash to rehash its internal data structure. This means the method can safely be called while iterating and will not affect the order of items in the multihash.

while (iter != hash.end() && iter.key() == obj) {
if (iter.value() == 0) {
iter = hash.erase(iter);
} else {
++iter;
}
}
See also
find(), remove(), take()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
iterator QMultiHash< Key, Val, Hash, KeyEqual >::find ( const Key &  key)
inline

Returns an iterator pointing to the item with the key in the multihash. If the multihash contains no matching items, returns end().

If the multihash contains multiple items with the same key, this method will return an iterator which points to the most recently inserted value. The other values are accessible by incrementing the iterator. The following code iterates over all the items with the same key.

while (iter != hash.end() && iter.key() == "SHOE") {
cout << iter.value() << endl;
++iter;
}
See also
value(), values()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
const_iterator QMultiHash< Key, Val, Hash, KeyEqual >::find ( const Key &  key) const
inline

Returns a const iterator pointing to the item with the key. If the multihash contains no matching item, returns end().

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::iterator QMultiHash< Key, Val, Hash, KeyEqual >::find ( const Key &  key,
const Val &  value 
)
inline

Returns an iterator pointing to the item with the given key and value. If the multihash contains no matching items, returns end(). If the multihash contains multiple items with the same key and value, the iterator returned points to some matching item.

See also
QMultiHash::find()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::const_iterator QMultiHash< Key, Val, Hash, KeyEqual >::find ( const Key &  key,
const Val &  value 
) const
inline

Returns a const iterator pointing to the item with the given key and value. If the multihash contains no matching items, returns end(). If the multihash contains multiple items with the same key and value, the iterator returned points to some matching item.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::iterator QMultiHash< Key, Val, Hash, KeyEqual >::insert ( const Key &  key,
const Val &  value 
)
inline

Inserts a new item with the key and a value of value. If there is already an item with the same key this method will create a new entry. This behavior is very different from replace() which overwrites the value of an existing item.

See also
replace()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
iterator QMultiHash< Key, Val, Hash, KeyEqual >::insert ( const std::pair< const Key, Val > &  data)
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 this method will create a new entry. This behavior is very different from replace() which overwrites the value of an existing item.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
iterator QMultiHash< Key, Val, Hash, KeyEqual >::insertMulti ( const Key &  key,
const Val &  value 
)
inline

Inserts a new item with the key and a value of value. If there is already an item with the same key this method will create a new entry. This behavior is very different from insert() which overwrites the value of an existing item.

See also
insert(), values()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
bool QMultiHash< Key, Val, Hash, KeyEqual >::isEmpty ( ) const
inline

Returns true if the multihash contains no items, otherwise returns false.

See also
size()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
const Key QMultiHash< Key, Val, Hash, KeyEqual >::key ( const Val &  value) const

Returns the first key mapped to value. If no item with the given value is found then a new value initialized object of type Key is returned. 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.

See also
value(), keys()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
const Key QMultiHash< Key, Val, Hash, KeyEqual >::key ( const Val &  value,
const Key &  defaultKey 
) const

Returns the key of the first item matching the given value. Otherwise, returns the given defaultKey.

This method can be slow (linear time) because the internal data structure is optimized for fast lookup by key, not by value.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QList< Key > QMultiHash< Key, Val, Hash, KeyEqual >::keys ( ) const

Returns a list containing all the keys in the multihash in an arbitrary order. Keys which occur multiple times, will also occur multiple times in the list. To obtain a list of unique keys, where each key from the multihash only occurs once, use uniqueKeys().

The order is guaranteed to be the same as when calling values().

See also
uniqueKeys(), values(), key()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
QList< Key > QMultiHash< Key, Val, Hash, KeyEqual >::keys ( const Val &  value) const

Returns a list containing all the keys matching the given value in an arbitrary order.

This method can be slow (linear time), because the internal data structure is optimized for fast lookup by key, not by value.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
bool QMultiHash< Key, Val, Hash, KeyEqual >::operator!= ( const QMultiHash< Key, Val, Hash, KeyEqual > &  other) const
inline

Returns true if other is not equal to this hash otherwise it returns false. Two hashes are considered equal if they contain the same (key, value) pairs.

This method requires the type T to support operator==().

See also
operator==()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash QMultiHash< Key, Val, Hash, KeyEqual >::operator+ ( const QMultiHash< Key, Val, Hash, KeyEqual > &  other) const
inline

Returns a QMultiHash which contains all of the items in this multihash plus all the items in other. If a key is common to both, the new multihash will contain the key multiple times.

See also
operator+=()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash & QMultiHash< Key, Val, Hash, KeyEqual >::operator+= ( const QMultiHash< Key, Val, Hash, KeyEqual > &  other)
inline

Inserts all the items in the given other multihash into this multihash, returns a reference to this QMultiHash.

See also
insert()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual > & QMultiHash< Key, Val, Hash, KeyEqual >::operator= ( const QMultiHash< Key, Val, Hash, KeyEqual > &  other)
default

Copy assigns from other and returns a reference to this object.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual > & QMultiHash< Key, Val, Hash, KeyEqual >::operator= ( QMultiHash< Key, Val, Hash, KeyEqual > &&  other)
default

Move assigns from other and returns a reference to this object.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
bool QMultiHash< Key, Val, Hash, KeyEqual >::operator== ( const QMultiHash< Key, Val, Hash, KeyEqual > &  other) const
inline

Returns true if other is equal to this hash, otherwise it returns false. Two hashes are considered equal if they contain the same (key, value) pairs.

This method requires the type T to support operator==().

See also
operator!=()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
Val & QMultiHash< Key, Val, Hash, KeyEqual >::operator[] ( const Key &  key)
inline

Returns a reference to the value for the element with the given key. If the multihash contains multiple items with the same key, this method will return a reference to the most recently inserted value. If the key was not found then a new value initialized object of type Val with the given key is inserted. A reference to the new element will be returned. Refer to default constructed elements for additional information.

See also
insert(), value()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
const Val QMultiHash< Key, Val, Hash, KeyEqual >::operator[] ( const Key &  key) const
inline

Equivalent to calling value().

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 then access the data by calling iter.value().

template<typename Key , typename Val , typename Hash , typename KeyEqual >
size_type QMultiHash< Key, Val, Hash, KeyEqual >::remove ( const Key &  key)
inline

Removes all the items matching the given key. Returns the number of items removed.

See also
clear(), take(), QMultiHash::remove()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::size_type QMultiHash< Key, Val, Hash, KeyEqual >::remove ( const Key &  key,
const Val &  value 
)

Removes all the items which match the given key and value. Returns the number of items removed.

See also
QMultiHash::remove()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::iterator QMultiHash< Key, Val, Hash, KeyEqual >::replace ( const Key &  key,
const Val &  value 
)
inline

Inserts a new item with the given key and value.

If there is already an item with the same key, then the value is replaced with the new given value. If there are multiple items with the same key, only the most recently inserted item's value is replaced with the given value.

See also
insert()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
void QMultiHash< Key, Val, Hash, KeyEqual >::reserve ( size_type  size)
inline

Ensures the internal hash table consists of at least size buckets. This method is useful for code which needs to build a huge hash and wants to avoid repeated reallocation.

hash.reserve(20000);
for (int i = 0; i < 20000; ++i) {
hash.insert(keys[i], values[i]);
}

Ideally, size should be slightly more than the maximum number of items expected in the hash. The size does not have to be prime, because QMultiHash will use a prime number internally. If size is an underestimate, the worst that will happen is that the QMultiHash will be a bit slower. You will rarely need to call this method. The internal hash table automatically shrinks or grows to provide good performance without wasting too much memory.

See also
squeeze(), capacity()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
size_type QMultiHash< Key, Val, Hash, KeyEqual >::size ( ) const
inline

Returns the number of items in the multihash.

See also
isEmpty(), count()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
void QMultiHash< Key, Val, Hash, KeyEqual >::squeeze ( )
inline

Reduces the size of the internal multihash table to save memory. The sole purpose of this method is to provide a means of fine tuning the memory usage. You will rarely need to call this method.

See also
reserve(), capacity()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
void QMultiHash< Key, Val, Hash, KeyEqual >::swap ( QMultiHash< Key, Val, Hash, KeyEqual > &  other)
inline

Swaps multihash other with this multihash. This operation is very fast and never fails.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
Val QMultiHash< Key, Val, Hash, KeyEqual >::take ( const Key &  key)
inline

Removes the item with the given key and returns the value. The element is then erased. If there are multiple items for the given key, the most recently inserted one is removed. If you do not use the return value calling remove() will be more efficient. If the key was not found then a new value initialized object of type Val with the given key 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.

See also
remove()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
QList< Key > QMultiHash< Key, Val, Hash, KeyEqual >::uniqueKeys ( ) const

Returns a list containing all the keys. Any key which occurs multiple times in the multihash will occur only once in the returned list.

See also
keys(), values()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual > & QMultiHash< Key, Val, Hash, KeyEqual >::unite ( const QMultiHash< Key, Val, Hash, KeyEqual > &  other)
inline

Inserts all the items in the other multihash into this multihash. If a key is common to both, this multihash will contain the key multiple times.

See also
insertMulti()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
Val QMultiHash< Key, Val, Hash, KeyEqual >::value ( const Key &  key) const
inline

Returns the value associated with the given key. If there are multiple items for the given key, the value of the most recently inserted item is returned. If no item with the given key is found, a new value initialized object of type Val with the given key 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().

See also
key(), values(), contains(), operator[]()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
Val QMultiHash< Key, Val, Hash, KeyEqual >::value ( const Key &  key,
const Val &  defaultValue 
) const
inline

Returns the value matching the given key. Otherwise, returns the defaultValue. If there are multiple items for the given key, the value of the most recently inserted item is returned.

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.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QList< Val > QMultiHash< Key, Val, Hash, KeyEqual >::values ( ) const

Returns a list containing all the values in the multihash in an arbitrary order. For keys which occur multiple times all of the values will occur in the list. The order is guaranteed to be the same as that used by keys().

See also
keys(), value()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
QList< Val > QMultiHash< Key, Val, Hash, KeyEqual >::values ( const Key &  key) const

Returns a list of all the values associated with the key from the most recently inserted to the least recently inserted.

See also
count(), insertMulti()

Friends And Related Function Documentation

QDataStream & operator<< ( QDataStream stream,
const QMultiHash< Key, Val, Hash, KeyEqual > &  hash 
)
related

Writes the given hash to the stream. Returns a reference to the stream. This function requires the type T to support operator<<().

Refer to Serializing Data Types for additional information.

QDataStream & operator>> ( QDataStream stream,
QMultiHash< Key, Val, Hash, KeyEqual > &  hash 
)
related

Reads from the stream into the given hash. Returns a reference to the stream. This function requires the type T to support operator>>().

Refer to Serializing Data Types for additional information.