Qt 4.8
|
The QMultiHash class is a convenience QHash subclass that provides multi-valued hashes. More...
#include <qcontainerfwd.h>
Public Functions | |
QHash< Key, T >::const_iterator | constFind (const Key &key, const T &value) const |
Returns an iterator pointing to the item with the key and the value in the hash. More... | |
bool | contains (const Key &key, const T &value) const |
Returns true if the hash contains an item with the key and value; otherwise returns false. More... | |
int | count (const Key &key, const T &value) const |
Returns the number of items with the key and value. More... | |
QHash< Key, T >::iterator | find (const Key &key, const T &value) |
Returns an iterator pointing to the item with the key and value. More... | |
QHash< Key, T >::const_iterator | find (const Key &key, const T &value) const |
QHash< Key, T >::iterator | insert (const Key &key, const T &value) |
Inserts a new item with the key and a value of value. More... | |
QMultiHash | operator+ (const QMultiHash &other) const |
Returns a hash that contains all the items in this hash in addition to all the items in other. More... | |
QMultiHash & | operator+= (const QMultiHash &other) |
Inserts all the items in the other hash into this hash and returns a reference to this hash. More... | |
QMultiHash () | |
Constructs an empty hash. More... | |
QMultiHash (const QHash< Key, T > &other) | |
Constructs a copy of other (which can be a QHash or a QMultiHash). More... | |
int | remove (const Key &key, const T &value) |
Removes all the items that have the key and the value value from the hash. More... | |
QHash< Key, T >::iterator | replace (const Key &key, const T &value) |
Inserts a new item with the key and a value of value. More... | |
void | swap (QMultiHash< Key, T > &other) |
Swaps hash other with this hash. More... | |
Public Functions inherited from QHash< Key, T > | |
iterator | begin () |
Returns an STL-style iterator pointing to the first item in the hash. More... | |
const_iterator | begin () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
int | capacity () const |
Returns the number of buckets in the QHash's internal hash table. More... | |
void | clear () |
Removes all items from the hash. More... | |
const_iterator | constBegin () const |
Returns a const STL-style iterator pointing to the first item in the hash. More... | |
const_iterator | constEnd () const |
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash. More... | |
const_iterator | constFind (const Key &key) const |
Returns an iterator pointing to the item with the key in the hash. More... | |
bool | contains (const Key &key) const |
Returns true if the hash contains an item with the key; otherwise returns false. More... | |
int | count (const Key &key) const |
Returns the number of items associated with the key. More... | |
int | count () const |
Same as size(). More... | |
void | detach () |
Detaches this hash from any other hashes with which it may share data. More... | |
bool | empty () const |
This function is provided for STL compatibility. More... | |
iterator | end () |
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash. More... | |
const_iterator | end () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
iterator | erase (iterator it) |
Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator to the next item in the hash. More... | |
iterator | find (const Key &key) |
Returns an iterator pointing to the item with the key in the hash. More... | |
const_iterator | find (const Key &key) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
iterator | insert (const Key &key, const T &value) |
Inserts a new item with the key and a value of value. More... | |
iterator | insertMulti (const Key &key, const T &value) |
Inserts a new item with the key and a value of value. More... | |
bool | isDetached () const |
Returns true if the hash's internal data isn't shared with any other hash object; otherwise returns false. More... | |
bool | isEmpty () const |
Returns true if the hash contains no items; otherwise returns false. More... | |
bool | isSharedWith (const QHash< Key, T > &other) const |
const Key | key (const T &value) const |
Returns the first key mapped to value. More... | |
const Key | key (const T &value, const Key &defaultKey) const |
Returns the first key mapped to value, or defaultKey if the hash contains no item mapped to value. More... | |
QList< Key > | keys () const |
Returns a list containing all the keys in the hash, in an arbitrary order. More... | |
QList< Key > | keys (const T &value) const |
Returns a list containing all the keys associated with value value, in an arbitrary order. More... | |
bool | operator!= (const QHash< Key, T > &other) const |
Returns true if other is not equal to this hash; otherwise returns false. More... | |
QHash< Key, T > & | operator= (const QHash< Key, T > &other) |
Assigns other to this hash and returns a reference to this hash. More... | |
bool | operator== (const QHash< Key, T > &other) const |
Returns true if other is equal to this hash; otherwise returns false. More... | |
T & | operator[] (const Key &key) |
Returns the value associated with the key as a modifiable reference. More... | |
const T | operator[] (const Key &key) const |
Same as value(). More... | |
QHash () | |
Constructs an empty hash. More... | |
QHash (const QHash< Key, T > &other) | |
Constructs a copy of other. More... | |
int | remove (const Key &key) |
Removes all the items that have the key from the hash. More... | |
void | reserve (int size) |
Ensures that the QHash's internal hash table consists of at least size buckets. More... | |
void | setSharable (bool sharable) |
int | size () const |
Returns the number of items in the hash. More... | |
void | squeeze () |
Reduces the size of the QHash's internal hash table to save memory. More... | |
void | swap (QHash< Key, T > &other) |
Swaps hash other with this hash. More... | |
T | take (const Key &key) |
Removes the item with the key from the hash and returns the value associated with it. More... | |
QList< Key > | uniqueKeys () const |
Returns a list containing all the keys in the map. More... | |
QHash< Key, T > & | unite (const QHash< Key, T > &other) |
Inserts all the items in the other hash into this hash. More... | |
const T | value (const Key &key) const |
Returns the value associated with the key. More... | |
const T | value (const Key &key, const T &defaultValue) const |
If the hash contains no item with the given key, the function returns defaultValue. More... | |
QList< T > | values () const |
Returns a list containing all the values in the hash, in an arbitrary order. More... | |
QList< T > | 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. More... | |
~QHash () | |
Destroys the hash. More... | |
Private Functions | |
T & | operator[] (const Key &key) |
const T | operator[] (const Key &key) const |
Additional Inherited Members | |
Public Types inherited from QHash< Key, T > | |
typedef const_iterator | ConstIterator |
Qt-style synonym for QHash::const_iterator. More... | |
typedef qptrdiff | difference_type |
Typedef for ptrdiff_t. More... | |
typedef iterator | Iterator |
Qt-style synonym for QHash::iterator. More... | |
typedef Key | key_type |
Typedef for Key. More... | |
typedef T | mapped_type |
Typedef for T. More... | |
typedef int | size_type |
Typedef for int. More... | |
Related Functions inherited from QHash< Key, T > | |
QDataStream & | operator<< (QDataStream &out, const QHash< Key, T > &hash) |
Writes the hash hash to stream out. More... | |
QDataStream & | operator>> (QDataStream &in, QHash< Key, T > &hash) |
Reads a hash from stream in into hash. More... | |
uint | qHash (const QPair< T1, T2 > &key) |
Returns the hash value for the key. More... | |
uint | qHash (char key) |
Returns the hash value for the key. More... | |
uint | qHash (uchar key) |
Returns the hash value for the key. More... | |
uint | qHash (signed char key) |
Returns the hash value for the key. More... | |
uint | qHash (ushort key) |
Returns the hash value for the key. More... | |
uint | qHash (short key) |
Returns the hash value for the key. More... | |
uint | qHash (uint key) |
Returns the hash value for the key. More... | |
uint | qHash (int key) |
Returns the hash value for the key. More... | |
uint | qHash (ulong key) |
Returns the hash value for the key. More... | |
uint | qHash (long key) |
Returns the hash value for the key. More... | |
uint | qHash (quint64 key) |
Returns the hash value for the key. More... | |
uint | qHash (qint64 key) |
Returns the hash value for the key. More... | |
uint | qHash (QChar key) |
Returns the hash value for the key. More... | |
uint | qHash (const QBitArray &key) |
uint | qHash (const QString &key) |
Returns the hash value for the key. More... | |
uint | qHash (const T *key) |
uint | qHash (const QXmlNodeModelIndex &index) |
Computes a hash key from the QXmlNodeModelIndex index, and returns it. More... | |
The QMultiHash class is a convenience QHash subclass that provides multi-valued hashes.
QMultiHash<Key, T> is one of Qt's generic container classes. It inherits QHash and extends it with a few convenience functions that make it more suitable than QHash for storing multi-valued hashes. A multi-valued hash is a hash that allows multiple values with the same key; QHash normally doesn't allow that, unless you call QHash::insertMulti().
Because QMultiHash inherits QHash, all of QHash's functionality also applies to QMultiHash. For example, you can use isEmpty() to test whether the hash is empty, and you can traverse a QMultiHash using QHash's iterator classes (for example, QHashIterator). But in addition, it provides an insert() function that corresponds to QHash::insertMulti(), and a replace() function that corresponds to QHash::insert(). It also provides convenient operator+() and operator+=().
Example:
Unlike QHash, QMultiHash provides no operator[]. Use value() or replace() if you want to access the most recently inserted item with a certain key.
If you want to retrieve all the values for a single key, you can use values(const Key &key), which returns a QList<T>:
The items that share the same key are available from most recently to least recently inserted.
A more efficient approach is to call find() to get the STL-style iterator for the first item with a key and iterate from there:
QMultiHash's key and value data types must be assignable data types. You cannot, for example, store a QWidget as a value; instead, store a QWidget *. In addition, QMultiHash's key type must provide operator==(), and there must also be a global qHash() function that returns a hash value for an argument of the key's type. See the QHash documentation for details.
Definition at line 58 of file qcontainerfwd.h.
|
inline |
|
inline |
Constructs a copy of other (which can be a QHash or a QMultiHash).
Definition at line 928 of file qhash.h.
|
inline |
Returns an iterator pointing to the item with the key and the value in the hash.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
If the hash contains no such item, the function returns constEnd().
Definition at line 992 of file qhash.h.
Referenced by QDBusConnectionPrivate::socketRead(), and QDBusConnectionPrivate::socketWrite().
Q_INLINE_TEMPLATE bool QMultiHash< Key, T >::contains | ( | const Key & | key, |
const T & | value | ||
) | const |
Returns true if the hash contains an item with the key and value; otherwise returns false.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 1000 of file qhash.h.
Q_INLINE_TEMPLATE int QMultiHash< Key, T >::count | ( | const Key & | key, |
const T & | value | ||
) | const |
Returns the number of items with the key and value.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 1023 of file qhash.h.
Referenced by QGraphicsAnchorLayoutPrivate::constraintsFromPaths().
|
inline |
Returns an iterator pointing to the item with the key and value.
If the hash contains no such item, the function returns end().
If the hash contains multiple items with the key and value, the iterator returned points to the most recently inserted item.
Definition at line 972 of file qhash.h.
Referenced by QMetaObject::changeGuard(), QObjectPrivate::clearGuards(), QDBusConnectionPrivate::connectRelay(), QDBusConnectionPrivate::connectSignal(), QDBusConnectionPrivate::disconnectRelay(), QDBusConnectionPrivate::disconnectSignal(), QDBusConnectionPrivate::handleSignal(), QTextFormatCollection::hasFormatCached(), QTextFormatCollection::indexForFormat(), qDBusRealToggleWatch(), qDBusRemoveWatch(), and QMetaObject::removeGuard().
|
inline |
Definition at line 982 of file qhash.h.
|
inline |
Inserts a new item with the key and a value of value.
If there is already an item with the same key in the hash, this function will simply create a new one. (This behavior is different from replace(), which overwrites the value of an existing item.)
Definition at line 934 of file qhash.h.
Referenced by QMetaObject::changeGuard(), QIcdEngine::doRequestUpdate(), QGraphicsAnchorLayoutPrivate::findPaths(), and QDBusConnectionPrivate::setConnection().
|
inline |
Returns a hash that contains all the items in this hash in addition to all the items in other.
If a key is common to both hashes, the resulting hash will contain the key multiple times.
Definition at line 939 of file qhash.h.
|
inline |
Inserts all the items in the other hash into this hash and returns a reference to this hash.
Definition at line 937 of file qhash.h.
|
private |
|
private |
Q_INLINE_TEMPLATE int QMultiHash< Key, T >::remove | ( | const Key & | key, |
const T & | value | ||
) |
Removes all the items that have the key and the value value from the hash.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the number of items removed.
Definition at line 1006 of file qhash.h.
Referenced by QIcdEngine::doRequestUpdate().
|
inline |
Inserts a new item with the key and a value of value.
If there is already an item with the 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.
Definition at line 931 of file qhash.h.
|
inline |
Swaps hash other with this hash.
This operation is very fast and never fails.
Definition at line 929 of file qhash.h.