📄 qhash.cpp
字号:
/*! \fn const Key &QHash::const_iterator::key() const Returns the current item's key. \sa value()*//*! \fn const T &QHash::const_iterator::value() const Returns the current item's value. \sa key(), operator*()*//*! \fn const T &QHash::const_iterator::operator*() const Returns the current item's value. Same as value(). \sa key()*//*! \fn const T *QHash::const_iterator::operator->() const Returns a pointer to the current item's value. \sa value()*//*! \fn bool QHash::const_iterator::operator==(const const_iterator &other) const Returns true if \a other points to the same item as this iterator; otherwise returns false. \sa operator!=()*//*! \fn bool QHash::const_iterator::operator!=(const const_iterator &other) const Returns true if \a other points to a different item than this iterator; otherwise returns false. \sa operator==()*//*! \fn QHash::const_iterator &QHash::const_iterator::operator++() The prefix ++ operator (\c{++i}) advances the iterator to the next item in the hash and returns an iterator to the new current item. Calling this function on QHash::end() leads to undefined results. \sa operator--()*//*! \fn QHash::const_iterator QHash::const_iterator::operator++(int) \overload The postfix ++ operator (\c{i++}) advances the iterator to the next item in the hash and returns an iterator to the previously current item.*//*! \fn QHash::const_iterator &QHash::const_iterator::operator--() The prefix -- operator (\c{--i}) makes the preceding item current and returns an iterator pointing to the new current item. Calling this function on QHash::begin() leads to undefined results. \sa operator++()*//*! \fn QHash::const_iterator QHash::const_iterator::operator--(int) \overload The postfix -- operator (\c{i--}) makes the preceding item current and returns an iterator pointing to the previously current item.*//*! \fn QHash::const_iterator QHash::const_iterator::operator+(int j) const Returns an iterator to the item at \a j positions forward from this iterator. (If \a j is negative, the iterator goes backward.) This operation can be slow for large \a j values. \sa operator-()*//*! \fn QHash::const_iterator QHash::const_iterator::operator-(int j) const Returns an iterator to the item at \a j positions backward from this iterator. (If \a j is negative, the iterator goes forward.) This operation can be slow for large \a j values. \sa operator+()*//*! \fn QHash::const_iterator &QHash::const_iterator::operator+=(int j) Advances the iterator by \a j items. (If \a j is negative, the iterator goes backward.) This operation can be slow for large \a j values. \sa operator-=(), operator+()*//*! \fn QHash::const_iterator &QHash::const_iterator::operator-=(int j) Makes the iterator go back by \a j items. (If \a j is negative, the iterator goes forward.) This operation can be slow for large \a j values. \sa operator+=(), operator-()*//*! \fn uint qHash(char key) \relates QHash Returns the hash value for \a key.*//*! \fn uint qHash(uchar key) \relates QHash \overload Returns the hash value for \a key.*//*! \fn uint qHash(signed char key) \relates QHash \overload Returns the hash value for \a key.*//*! \fn uint qHash(ushort key) \relates QHash \overload Returns the hash value for \a key.*//*! \fn uint qHash(short key) \relates QHash \overload Returns the hash value for \a key.*//*! \fn uint qHash(uint key) \relates QHash \overload Returns the hash value for \a key.*//*! \fn uint qHash(int key) \relates QHash \overload Returns the hash value for \a key.*//*! \fn uint qHash(ulong key) \relates QHash \overload Returns the hash value for \a key.*//*! \fn uint qHash(long key) \relates QHash \overload Returns the hash value for \a key.*//*! \fn uint qHash(quint64 key) \relates QHash \overload Returns the hash value for \a key.*//*! \fn uint qHash(qint64 key) \relates QHash \overload Returns the hash value for \a key.*//*! \fn uint qHash(QChar key) \relates QHash \overload Returns the hash value for \a key.*//*! \fn uint qHash(const QByteArray &key) \fn uint qHash(const QBitArray &key) \relates QHash \overload Returns the hash value for \a key.*//*! \fn uint qHash(const QString &key) \relates QHash \overload Returns the hash value for \a key.*//*! \fn uint qHash(const T *key) \relates QHash \overload Returns the hash value for \a key.*//*! \fn uint qHash(const QPair<T1, T2> &key) \relates QHash \since 4.3 Returns the hash value for \a key. Types \c T1 and \c T2 must be supported by qHash().*//*! \fn QDataStream &operator<<(QDataStream &out, const QHash<Key, T>& hash) \relates QHash Writes the hash \a hash to stream \a out. This function requires the key and value types to implement \c operator<<(). \sa {Format of the QDataStream operators}*//*! \fn QDataStream &operator>>(QDataStream &in, QHash<Key, T> &hash) \relates QHash Reads a hash from stream \a in into \a hash. This function requires the key and value types to implement \c operator>>(). \sa {Format of the QDataStream operators}*//*! \class QMultiHash \brief The QMultiHash class is a convenience QHash subclass that provides multi-valued hashes. \ingroup tools \ingroup shared \mainclass \reentrant QMultiHash\<Key, T\> is one of Qt's generic \l{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: \code 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 \endcode 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>: \code QList<int> values = hash.values("plenty"); for (int i = 0; i < values.size(); ++i) cout << values.at(i) << endl; \endcode 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: \code QMultiHash<QString, int>::iterator i = hash.find("plenty"); while (i != hash.end() && i.key() == "plenty") { cout << i.value() << endl; ++i; } \endcode QMultiHash's key and value data types must be \l{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. \sa QHash, QHashIterator, QMutableHashIterator, QMultiMap*//*! \fn QMultiHash::QMultiHash() Constructs an empty hash.*//*! \fn QMultiHash::QMultiHash(const QHash<Key, T> &other) Constructs a copy of \a other (which can be a QHash or a QMultiHash). \sa operator=()*//*! \fn QMultiHash::iterator QMultiHash::replace(const Key &key, const T &value) Inserts a new item with the key \a key and a value of \a value. If there is already an item with the key \a key, that item's value is replaced with \a value. If there are multiple items with the key \a key, the most recently inserted item's value is replaced with \a value. \sa insert()*//*! \fn QMultiHash::iterator QMultiHash::insert(const Key &key, const T &value) Inserts a new item with the key \a key and a value of \a 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.) \sa replace()*//*! \fn QMultiHash &QMultiHash::operator+=(const QMultiHash &other) Inserts all the items in the \a other hash into this hash and returns a reference to this hash. \sa insert()*//*! \fn QMultiHash QMultiHash::operator+(const QMultiHash &other) const Returns a hash that contains all the items in this hash in addition to all the items in \a other. If a key is common to both hashes, the resulting hash will contain the key multiple times. \sa operator+=()*//*! \fn bool QMultiHash::contains(const Key &key, const T &value) const \since 4.3 Returns true if the hash contains an item with key \a key and value \a value; otherwise returns false. \sa QHash::contains()*//*! \fn bool QMultiHash::contains(const Key &key) const \overload \sa QHash::contains()*//*! \fn int QMultiHash::remove(const Key &key, const T &value) \since 4.3 Removes all the items that have the key \a key and the value \a value from the hash. Returns the number of items removed. \sa QHash::remove()*//*! \fn int QMultiHash::remove(const Key &key) \overload \sa QHash::remove()*//*! \fn int QMultiHash::count(const Key &key, const T &value) const \since 4.3 Returns the number of items with key \a key and value \a value. \sa QHash::count()*//*! \fn int QMultiHash::count(const Key &key) const \overload \sa QHash::count()*//*! \fn int QMultiHash::count() const \overload \sa QHash::count()*//*! \fn typename QHash<Key, T>::iterator QMultiHash::find(const Key &key, const T &value) \since 4.3 Returns an iterator pointing to the item with key \a key and value \a value in the hash. If the hash contains no such item, the function returns end(). If the hash contains multiple items with key \a key, this function returns an iterator that points to the most recently inserted value. \sa QHash::find()*//*! \fn typename QHash<Key, T>::iterator QMultiHash::find(const Key &key) \overload \sa QHash::find()*//*! \fn typename QHash<Key, T>::const_iterator QMultiHash::find(const Key &key, const T &value) const \since 4.3 \overload*//*! \fn typename QHash<Key, T>::const_iterator QMultiHash::find(const Key &key) const \overload \sa QHash::find()*//*! \fn typename QHash<Key, T>::const_iterator QMultiHash::constFind(const Key &key, const T &value) const \since 4.3 Returns an iterator pointing to the item with key \a key and the value \a value in the hash. If the hash contains no such item, the function returns constEnd(). \sa QHash::constFind()*//*! \fn typename QHash<Key, T>::const_iterator QMultiHash::constFind(const Key &key) const \overload \sa QHash::constFind()*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -