The QMultiHash class is a convenience QHash 子類,提供多值哈希。 更多...
| 頭: | #include <QMultiHash> |
| qmake: | QT += core |
| 繼承: | QHash |
注意: 此類的所有函數 可重入 .
| QMultiHash () | |
| QMultiHash (std::initializer_list<std::pair<Key, T> > list ) | |
| QMultiHash (const QHash<Key, T> & other ) | |
| QMultiHash (QHash<Key, T> && other ) | |
| typename QHash<Key, T>::const_iterator | constFind (const Key & key , const T & value ) const |
| bool | contains (const Key & key , const T & value ) const |
| int | count (const Key & key , const T & value ) const |
| typename QHash<Key, T>::iterator | find (const Key & key , const T & value ) |
| typename QHash<Key, T>::const_iterator | find (const Key & key , const T & value ) const |
| typename QHash<Key, T>::iterator | insert (const Key & key , const T & value ) |
| int | remove (const Key & key , const T & value ) |
| typename QHash<Key, T>::iterator | replace (const Key & key , const T & value ) |
| void | swap (QMultiHash<K, V> & other ) |
| QMultiHash<K, V> | operator+ (const QMultiHash<K, V> & other ) const |
| QMultiHash<K, V> & | operator+= (const QMultiHash<K, V> & other ) |
| uint | qHash (const QMultiHash<Key, T> & key , uint seed = ...) |
The QMultiHash class is a convenience QHash 子類,提供多值哈希。
QMultiHash <Key, T> 是一種 Qt 一般 容器類 . 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 ().
因為 QMultiHash 繼承 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 使用 QHash 的迭代器類 (例如: QHashIterator ). But in addition, it provides an insert () function that corresponds to QHash::insertMulti (), 和 replace () function that corresponds to QHash::insert (). It also provides convenient operator+() and operator+=().
範例:
QMultiHash<QString, int> hash1, hash2, hash3; hash1.insert("plenty", 100); hash1.insert("plenty", 2000); // hash1.size() == 2 hash2.insert("plenty", 5000); // hash2.size() == 1 hash3 = hash1 + hash2; // hash3.size() == 3
不像 QHash , QMultiHash provides no operator[]. Use value () 或 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>:
QList<int> values = hash.values("plenty"); for (int i = 0; i < values.size(); ++i) cout << values.at(i) << endl;
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<QString, int>::iterator i = hash.find("plenty"); while (i != hash.end() && i.key() == "plenty") { cout << i.value() << endl; ++i; }
QMultiHash 's key and value data types must be 可賦值數據類型 。例如,無法存儲 QWidget 作為值;取而代之,存儲 QWidget *. In addition, QMultiHash 's key type must provide operator==(), and there must also be a qHash () function in the type's namespace that returns a hash value for an argument of the key's type. See the QHash 文檔編製瞭解細節。
另請參閱 QHash , QHashIterator , QMutableHashIterator ,和 QMultiMap .
構造空哈希。
Constructs a multi-hash with a copy of each of the elements in the initializer list list .
This function is only available if the program is being compiled in C++11 mode.
該函數在 Qt 5.1 引入。
構造副本為 other (which can be a QHash 或 QMultiHash ).
另請參閱 operator= ().
Default constructs an instance of QMultiHash.
返迴迭代器指嚮的項具有 key 和 value 在哈希中。
If the hash contains no such item, the function returns constEnd ().
該函數在 Qt 4.3 引入。
另請參閱 QHash::constFind ().
返迴
true
若哈希包含的項具有
key
and
value
;否則返迴
false
.
該函數在 Qt 4.3 引入。
另請參閱 QHash::contains ().
Returns the number of items with the key and value .
該函數在 Qt 4.3 引入。
另請參閱 QHash::count ().
返迴迭代器指嚮的項具有 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.
該函數在 Qt 4.3 引入。
另請參閱 QHash::find ().
這是重載函數。
該函數在 Qt 4.3 引入。
插入新項具有 key 和值 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.)
另請參閱 replace ().
Removes all the items that have the key and the value value from the hash. Returns the number of items removed.
該函數在 Qt 4.3 引入。
另請參閱 QHash::remove ().
插入新項具有 key 和值 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 .
另請參閱 insert ().
交換哈希 other with this hash. This operation is very fast and never fails.
該函數在 Qt 4.8 引入。
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.
另請參閱 operator+= ().
Inserts all the items in the other hash into this hash and returns a reference to this hash.
另請參閱 insert ().
返迴哈希值為 key ,使用 seed 做計算種子。
類型
T
must be supported by
qHash
().
該函數在 Qt 5.8 引入。