The QHash 类是提供基于哈希表的字典的模板类。 更多...
头: | #include <QHash> |
qmake: | QT += core |
继承者: | QMultiHash |
注意: 此类的所有函数 可重入 .
class | const_iterator |
class | iterator |
class | key_iterator |
typedef | ConstIterator |
typedef | Iterator |
typedef | difference_type |
typedef | key_type |
typedef | mapped_type |
typedef | size_type |
QHash () | |
QHash (std::initializer_list<std::pair<Key, T> > list ) | |
QHash (const QHash & other ) | |
QHash (QHash && other ) | |
~QHash () | |
iterator | begin () |
const_iterator | begin () const |
int | 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 |
bool | contains (const Key & key ) const |
int | count (const Key & key ) const |
int | count () 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 pos ) |
iterator | erase (iterator pos ) |
iterator | find (const Key & key ) |
const_iterator | find (const Key & key ) const |
iterator | insert (const Key & key , const T & value ) |
iterator | insertMulti (const Key & key , const T & value ) |
bool | isEmpty () const |
const Key | key (const T & value ) const |
const Key | key (const T & value , const Key & defaultKey ) const |
key_iterator | keyBegin () const |
key_iterator | keyEnd () const |
QList<Key> | keys () const |
QList<Key> | keys (const T & value ) const |
int | remove (const Key & key ) |
void | reserve (int size ) |
int | size () const |
void | squeeze () |
void | swap (QHash & other ) |
T | take (const Key & key ) |
QList<Key> | uniqueKeys () const |
QHash & | unite (const QHash & other ) |
const T | value (const Key & key ) const |
const T | value (const Key & key , const T & defaultValue ) const |
QList<T> | values () const |
QList<T> | values (const Key & key ) const |
bool | operator!= (const QHash & other ) const |
QHash & | operator= (const QHash & other ) |
QHash & | operator= (QHash && other ) |
bool | operator== (const QHash & other ) const |
T & | operator[] (const Key & key ) |
const T | operator[] (const Key & key ) const |
int | qGlobalQHashSeed () |
uint | qHash (const QXmlNodeModelIndex & index ) |
uint | qHash (const QUrl & url , uint seed = 0) |
uint | qHash (const QDateTime & key , uint seed = 0) |
uint | qHash (const QDate & key , uint seed = 0) |
uint | qHash (const QTime & key , uint seed = 0) |
uint | qHash (const QPair<T1, T2> & key , uint seed = 0) |
uint | qHash (const std::pair<T1, T2> & key , uint seed = 0) |
uint | qHash (char key , uint seed = 0) |
uint | qHash (uchar key , uint seed = 0) |
uint | qHash (signed char key , uint seed = 0) |
uint | qHash (ushort key , uint seed = 0) |
uint | qHash (short key , uint seed = 0) |
uint | qHash (uint key , uint seed = 0) |
uint | qHash (int key , uint seed = 0) |
uint | qHash (ulong key , uint seed = 0) |
uint | qHash (long key , uint seed = 0) |
uint | qHash (quint64 key , uint seed = 0) |
uint | qHash (qint64 key , uint seed = 0) |
uint | qHash (float key , uint seed = 0) |
uint | qHash (double key , uint seed = 0) |
uint | qHash (const QChar key , uint seed = 0) |
uint | qHash (const QByteArray & key , uint seed = 0) |
uint | qHash (const QBitArray & key , uint seed = 0) |
uint | qHash (const QString & key , uint seed = 0) |
uint | qHash (const QStringRef & key , uint seed = 0) |
uint | qHash (QLatin1String key , uint seed = 0) |
uint | qHash (const T * key , uint seed = 0) |
uint | qHash (const QHash<Key, T> & key , uint seed = 0) |
uint | qHash (const QSet<T> & key , uint seed = 0) |
uint | qHash (const QVersionNumber & key , uint seed = 0) |
uint | qHash (const QSslCertificate & key , uint seed = 0) |
uint | qHash (QSslEllipticCurve curve , uint seed = 0) |
uint | qHash (const QSslError & key , uint seed = 0) |
uint | qHash (const QGeoCoordinate & coordinate , uint seed = 0) |
uint | qHashBits (const void * p , size_t len , uint seed = 0) |
uint | qHashRange (InputIterator first , InputIterator last , uint seed = 0) |
uint | qHashRangeCommutative (InputIterator first , InputIterator last , uint seed = 0) |
void | qSetGlobalQHashSeed (int newSeed ) |
QDataStream & | operator<< (QDataStream & out , const QHash<Key, T> & hash ) |
QDataStream & | operator>> (QDataStream & in , QHash<Key, T> & hash ) |
The QHash 类是提供基于哈希表的字典的模板类。
QHash <Key, T> 是一种 Qt 一般 容器类 。它存储 (键,值) 对,并提供键关联值的非常快速查找。
这里是范例
QHash
with
QString
键和
int
值:
QHash<QString, int> hash;
要将 (键,值) 对插入哈希,可以使用 operator[]():
hash["one"] = 1; hash["three"] = 3; hash["seven"] = 7;
This inserts the following three (key, value) pairs into the QHash : ("one", 1), ("three", 3), and ("seven", 7). Another way to insert items into the hash is to use insert ():
hash.insert("twelve", 12);
要查找值,使用 operator[]() 或 value ():
int num1 = hash["thirteen"]; int num2 = hash.value("thirteen");
If there is no item with the specified key in the hash, these functions return a 默认构造值 .
If you want to check whether the hash contains a particular key, use contains ():
int timeout = 30; if (hash.contains("TIMEOUT")) timeout = hash.value("TIMEOUT");
There is also a value () overload that uses its second argument as a default value if there is no item with the specified key:
int timeout = hash.value("TIMEOUT", 30);
In general, we recommend that you use contains () 和 value () rather than operator[]() for looking up a key in a hash. The reason is that operator[]() silently inserts an item into the hash if no item exists with the same key (unless the hash is const). For example, the following code snippet will create 1000 items in memory:
// WRONG QHash<int, QWidget *> hash; ... for (int i = 0; i < 1000; ++i) { if (hash[i] == okButton) cout << "Found button at index " << i << endl; }
要避免此问题,替换
hash[i]
with
hash.value(i)
在以上代码中。
在内部,
QHash
uses a hash table to perform lookups. Unlike Qt 3's
QDict
class, which needed to be initialized with a prime number,
QHash
's hash table automatically grows and shrinks to provide fast lookups without wasting too much memory. You can still control the size of the hash table by calling
reserve
() if you already know approximately how many items the
QHash
will contain, but this isn't necessary to obtain good performance. You can also call
capacity
() to retrieve the hash table's size.
If you want to navigate through all the (key, value) pairs stored in a QHash , you can use an iterator. QHash provides both Java 风格迭代器 ( QHashIterator and QMutableHashIterator ) 和 STL 样式迭代器 ( QHash::const_iterator and QHash::iterator ). Here's how to iterate over a QHash < QString , int> using a Java-style iterator:
QHashIterator<QString, int> i(hash); while (i.hasNext()) { i.next(); cout << i.key() << ": " << i.value() << endl; }
Here's the same code, but using an STL-style iterator:
QHash<QString, int>::const_iterator i = hash.constBegin(); while (i != hash.constEnd()) { cout << i.key() << ": " << i.value() << endl; ++i; }
QHash is unordered, so an iterator's sequence cannot be assumed to be predictable. If ordering by key is required, use a QMap .
Normally, a QHash allows only one value per key. If you call insert () with a key that already exists in the QHash , the previous value is erased. For example:
hash.insert("plenty", 100); hash.insert("plenty", 2000); // hash.value("plenty") == 2000
However, you can store multiple values per key by using insertMulti () 而不是 insert () (or using the convenience subclass QMultiHash ). 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 iterator for the first item with a key and iterate from there:
QHash<QString, int>::iterator i = hash.find("plenty"); while (i != hash.end() && i.key() == "plenty") { cout << i.value() << endl; ++i; }
If you only need to extract the values from a hash (not the keys), you can also use foreach :
QHash<QString, int> hash; ... foreach (int value, hash) cout << value << endl;
Items can be removed from the hash in several ways. One way is to call remove (); this will remove any item with the given key. Another way is to use QMutableHashIterator::remove (). In addition, you can clear the entire hash using clear ().
QHash 's key and value data types must be 可赋值数据类型 。例如,无法存储 QWidget 作为值;取而代之,存储 QWidget *.
A QHash 's key type has additional requirements other than being an assignable data type: it 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.
The
qHash
() function computes a numeric value based on a key. It can use any algorithm imaginable, as long as it always returns the same value if given the same argument. In other words, if
e1 == e2
,那么
qHash(e1) == qHash(e2)
must hold as well. However, to obtain good performance, the
qHash
() function should attempt to return different hash values for different keys to the largest extent possible.
For a key type
K
,
qHash
function must have one of these signatures:
uint qHash(K key); uint qHash(const K &key); uint qHash(K key, uint seed); uint qHash(const K &key, uint seed);
The two-arguments overloads take an unsigned integer that should be used to seed the calculation of the hash function. This seed is provided by QHash in order to prevent a family of algorithmic complexity attacks . If both a one-argument and a two-arguments overload are defined for a key type, the latter is used by QHash (note that you can simply define a two-arguments version, and use a default value for the seed parameter).
Here's a partial list of the C++ and Qt types that can serve as keys in a
QHash
: any integer type (char, unsigned long, etc.), any pointer type,
QChar
,
QString
,和
QByteArray
. For all of these, the
<QHash>
header defines a
qHash
() function that computes an adequate hash value. Many other Qt classes also declare a
qHash
overload for their type; please refer to the documentation of each class.
If you want to use other types as the key, make sure that you provide operator==() and a qHash () 实现。
范例:
#ifndef EMPLOYEE_H #define EMPLOYEE_H class Employee { public: Employee() {} Employee(const QString &name, const QDate &dateOfBirth); ... private: QString myName; QDate myDateOfBirth; }; inline bool operator==(const Employee &e1, const Employee &e2) { return e1.name() == e2.name() && e1.dateOfBirth() == e2.dateOfBirth(); } inline uint qHash(const Employee &key, uint seed) { return qHash(key.name(), seed) ^ key.dateOfBirth().day(); } #endif // EMPLOYEE_H
In the example above, we've relied on Qt's global qHash (const QString &, uint) to give us a hash value for the employee's name, and XOR'ed this with the day they were born to help produce unique hashes for people with the same name.
Note that the implementation of the qHash () overloads offered by Qt may change at any time. You 不必 rely on the fact that qHash () will give the same results (for the same inputs) across different Qt versions.
All hash tables are vulnerable to a particular class of denial of service attacks, in which the attacker carefully pre-computes a set of different keys that are going to be hashed in the same bucket of a hash table (or even have the very same hash value). The attack aims at getting the worst-case algorithmic behavior (O(n) instead of amortized O(1), see 算法的复杂性 for the details) when the data is fed into the table.
In order to avoid this worst-case behavior, the calculation of the hash value done by qHash () can be salted by a random seed, that nullifies the attack's extent. This seed is automatically generated by QHash once per process, and then passed by QHash as the second argument of the two-arguments overload of the qHash () 函数。
This randomization of
QHash
is enabled by default. Even though programs should never depend on a particular
QHash
ordering, there may be situations where you temporarily need deterministic behavior, for example for debugging or regression testing. To disable the randomization, define the environment variable
QT_HASH_SEED
. The contents of that variable, interpreted as a decimal value, will be used as the seed for
qHash
(). Alternatively, you can call the
qSetGlobalQHashSeed
() 函数。
另请参阅 QHashIterator , QMutableHashIterator , QMap ,和 QSet .
Qt 样式同义词 QHash::const_iterator .
Qt 样式同义词 QHash::iterator .
typedef 对于 ptrdiff_t。为兼容 STL 提供。
typedef 对于 Key。为兼容 STL 提供。
typedef 对于 T。为兼容 STL 提供。
typedef 对于 int。为兼容 STL 提供。
构造空哈希。
另请参阅 clear ().
Constructs a 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 .
This operation occurs in 常量时间 ,因为 QHash is 隐式共享 . This makes returning a QHash from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and this takes 线性时间 .
另请参阅 operator= ().
移动构造 QHash 实例,使之指向同一对象如 other 所指向的。
该函数在 Qt 5.2 引入。
Destroys the hash. References to the values in the hash and all iterators of this hash become invalid.
返回 STL 样式迭代器 指向哈希中的首项。
另请参阅 constBegin () 和 end ().
这是重载函数。
Returns the number of buckets in the QHash 的内部哈希表。
The sole purpose of this function is to provide a means of fine tuning QHash 's memory usage. In general, you will rarely ever need to call this function. If you want to know how many items are in the hash, call size ().
返回常量 STL 样式迭代器 指向哈希中的首项。
该函数在 Qt 5.0 引入。
返回常量 STL 样式迭代器 pointing to the imaginary item after the last item in the hash.
该函数在 Qt 5.0 引入。
从哈希移除所有项。
另请参阅 remove ().
返回常量 STL 样式迭代器 指向哈希中的首项。
返回常量 STL 样式迭代器 pointing to the imaginary item after the last item in the hash.
另请参阅 constBegin () 和 end ().
返回迭代器指向的项具有 key 在哈希中。
若哈希包含的项不具有 key ,函数返回 constEnd ().
该函数在 Qt 4.1 引入。
另请参阅 find () 和 QMultiHash::constFind ().
返回
true
若哈希包含的项具有
key
;否则返回
false
.
另请参阅 count () 和 QMultiHash::contains ().
返回项数关联 key .
另请参阅 contains () 和 insertMulti ().
这是重载函数。
如同 size ().
此函数为兼容 STL (标准模板库) 提供。它相当于
isEmpty
(), returning true if the hash is empty; otherwise returns
false
.
返回 STL 样式迭代器 pointing to the imaginary item after the last item in the hash.
这是重载函数。
Returns a pair of iterators delimiting the range of values
[first, second)
, that are stored under
key
. If the range is empty then both iterators will be equal to
end
().
该函数在 Qt 5.7 引入。
这是重载函数。
该函数在 Qt 5.7 引入。
Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator to the next item in the hash.
不像 remove () 和 take (), this function never causes QHash to rehash its internal data structure. This means that it can safely be called while iterating, and won't affect the order of items in the hash. For example:
QHash<QObject *, int> objectHash; ... QHash<QObject *, int>::iterator i = objectHash.find(obj); while (i != objectHash.end() && i.key() == obj) { if (i.value() == 0) { i = objectHash.erase(i); } else { ++i; } }
该函数在 Qt 5.7 引入。
另请参阅 remove (), take (),和 find ().
这是重载函数。
返回迭代器指向的项具有 key 在哈希中。
若哈希包含的项不具有 key ,函数返回 end ().
If the hash contains multiple items with the key , this function returns an iterator that points to the most recently inserted value. The other values are accessible by incrementing the iterator. For example, here's some code that iterates over all the items with the same key:
QHash<QString, int> hash; ... QHash<QString, int>::const_iterator i = hash.find("HDR"); while (i != hash.end() && i.key() == "HDR") { cout << i.value() << endl; ++i; }
另请参阅 value (), values (),和 QMultiHash::find ().
这是重载函数。
插入新项具有 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 .
另请参阅 insertMulti ().
插入新项具有 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 insert (), which overwrites the value of an existing item.)
返回
true
if the hash contains no items; otherwise returns false.
另请参阅 size ().
Returns the first key mapped to value .
若哈希包含的项不具有 value , the function returns a default-constructed key .
此函数可能很慢 ( 线性时间 ),因为 QHash 's internal data structure is optimized for fast lookup by key, not by value.
这是重载函数。
Returns the first key mapped to value ,或 defaultKey if the hash contains no item mapped to value .
此函数可能很慢 ( 线性时间 ),因为 QHash 's internal data structure is optimized for fast lookup by key, not by value.
该函数在 Qt 4.3 引入。
返回常量 STL 样式迭代器 指向哈希中的第一个 Key。
该函数在 Qt 5.6 引入。
另请参阅 keyEnd ().
返回常量 STL 样式迭代器 pointing to the imaginary item after the last key in the hash.
该函数在 Qt 5.6 引入。
另请参阅 keyBegin ().
Returns a list containing all the keys in the hash, in an arbitrary order. Keys that occur multiple times in the hash (because items were inserted with insertMulti (),或 unite () was used) also occur multiple times in the list.
To obtain a list of unique keys, where each key from the map only occurs once, use uniqueKeys ().
The order is guaranteed to be the same as that used by values ().
另请参阅 uniqueKeys (), values (),和 key ().
这是重载函数。
Returns a list containing all the keys associated with value value ,按任意次序。
此函数可能很慢 ( 线性时间 ),因为 QHash 's internal data structure is optimized for fast lookup by key, not by value.
Removes all the items that have the key from the hash. Returns the number of items removed which is usually 1 but will be 0 if the key isn't in the hash, or greater than 1 if insertMulti () has been used with the key .
另请参阅 clear (), take (),和 QMultiHash::remove ().
确保 QHash 's internal hash table consists of at least size buckets.
This function is useful for code that needs to build a huge hash and wants to avoid repeated reallocation. For example:
QHash<QString, int> hash; 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. size doesn't have to be prime, because QHash will use a prime number internally anyway. If size is an underestimate, the worst that will happen is that the QHash will be a bit slower.
In general, you will rarely ever need to call this function. QHash 's internal hash table automatically shrinks or grows to provide good performance without wasting too much memory.
另请参阅 squeeze () 和 capacity ().
返回哈希中的项数。
Reduces the size of the QHash 's internal hash table to save memory.
The sole purpose of this function is to provide a means of fine tuning QHash 's memory usage. In general, you will rarely ever need to call this function.
另请参阅 reserve () 和 capacity ().
交换哈希 other with this hash. This operation is very fast and never fails.
该函数在 Qt 4.8 引入。
Removes the item with the key from the hash and returns the value associated with it.
If the item does not exist in the hash, the function simply returns a 默认构造值 . If there are multiple items for key in the hash, only the most recently inserted one is removed.
若不使用返回值, remove () 效率更高。
另请参阅 remove ().
Returns a list containing all the keys in the map. Keys that occur multiple times in the map (because items were inserted with insertMulti (),或 unite () was used) occur only once in the returned list.
该函数在 Qt 4.2 引入。
Inserts all the items in the other hash into this hash. If a key is common to both hashes, the resulting hash will contain the key multiple times.
另请参阅 insertMulti ().
返回值关联 key .
若哈希包含的项不具有 key , the function returns a 默认构造值 . If there are multiple items for the key in the hash, the value of the most recently inserted one is returned.
另请参阅 key (), values (), contains (),和 operator[] ().
这是重载函数。
If the hash contains no item with the given key ,函数返回 defaultValue .
Returns a list containing all the values in the hash, in an arbitrary order. If a key is associated with multiple values, all of its values will be in the list, and not just the most recently inserted one.
The order is guaranteed to be the same as that used by keys ().
这是重载函数。
Returns a list of all the values associated with the key , from the most recently inserted to the least recently inserted.
另请参阅 count () 和 insertMulti ().
返回
true
if
other
不等于此哈希;否则返回
false
.
Two hashes are considered equal if they contain the same (key, value) pairs.
This function requires the value type to implement
operator==()
.
另请参阅 operator== ().
赋值 other to this hash and returns a reference to this hash.
移动赋值 other 到此 QHash 实例。
该函数在 Qt 5.2 引入。
返回
true
if
other
is equal to this hash; otherwise returns false.
Two hashes are considered equal if they contain the same (key, value) pairs.
This function requires the value type to implement
operator==()
.
另请参阅 operator!= ().
返回值关联 key 作为可修改引用。
若哈希包含的项不具有 key , the function inserts a 默认构造值 into the hash with the key , and returns a reference to it. If the hash contains multiple items with the key , this function returns a reference to the most recently inserted value.
这是重载函数。
如同 value ().
Returns the current global QHash seed.
The seed is set in any newly created QHash 。见 qHash about how this seed is being used by QHash .
该函数在 Qt 5.6 引入。
另请参阅 qSetGlobalQHashSeed .
Computes a hash key from the QXmlNodeModelIndex index , and returns it. This function would be used by QHash if you wanted to build a hash table for instances of QXmlNodeModelIndex .
The hash is computed on QXmlNodeModelIndex::data (), QXmlNodeModelIndex::additionalData (),和 QXmlNodeModelIndex::model (). This means the hash key can be used for node indexes from different node models.
该函数在 Qt 4.4 引入。
返回哈希值为 url 。若指定, seed 用于初始化哈希。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
类型
T1
and
T2
must be supported by
qHash
().
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
类型
T1
and
T2
must be supported by
qHash
().
注意: The return type of this function is not the same as that of
qHash(qMakePair(key.first, key.second), seed);
The two functions use different hashing algorithms; due to binary compatibility constraints, we cannot change the QPair algorithm to match the std::pair one before Qt 6.
该函数在 Qt 5.7 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.3 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.3 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.0 引入。
返回哈希值为 key ,使用 seed 做计算种子。
类型
T
must be supported by
qHash
().
该函数在 Qt 5.8 引入。
返回哈希值为 key ,使用 seed 做计算种子。
The hash value is independent of the order of elements in key , that is, sets that contain the same elements hash to the same value.
该函数在 Qt 5.5 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.6 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.4 引入。
Returns an hash value for the curve curve ,使用 seed 做计算种子。
该函数在 Qt 5.5 引入。
返回哈希值为 key ,使用 seed 做计算种子。
该函数在 Qt 5.4 引入。
Returns a hash value for coordinate ,使用 seed 做计算种子。
该函数在 Qt 5.7 引入。
Returns the hash value for the memory block of size len pointed to by p ,使用 seed 做计算种子。
Use this function only to implement qHash () for your own custom types. For example, here's how you could implement a qHash () overload for std::vector<int>:
inline uint qHash(const std::vector<int> &key, uint seed = 0) { if (key.empty()) return seed; else return qHashBits(&key.front(), key.size() * sizeof(int), seed); }
This takes advantage of the fact that std::vector lays out its data contiguously. If that is not the case, or the contained type has padding, you should use qHashRange () 代替。
It bears repeating that the implementation of qHashBits() - like the qHash () overloads offered by Qt - may change at any time. You 不必 rely on the fact that qHashBits() will give the same results (for the same inputs) across different Qt versions.
该函数在 Qt 5.4 引入。
另请参阅 qHashRange () 和 qHashRangeCommutative ().
Returns the hash value for the range [ first , last ), using seed to seed the calculation, by successively applying qHash () to each element and combining the hash values into a single one.
The return value of this function depends on the order of elements in the range. That means that
{0, 1, 2}
and
{1, 2, 0}
hash to different values. If order does not matter, for example for hash tables, use qHashRangeCommutative () instead. If you are hashing raw memory, use qHashBits ().
Use this function only to implement qHash () for your own custom types. For example, here's how you could implement a qHash () overload for std::vector<int>:
inline uint qHash(const std::vector<int> &key, uint seed = 0) { return qHashRange(key.begin(), key.end(), seed); }
It bears repeating that the implementation of qHashRange() - like the qHash () overloads offered by Qt - may change at any time. You 不必 rely on the fact that qHashRange() will give the same results (for the same inputs) across different Qt versions, even if qHash () for the element type would.
该函数在 Qt 5.5 引入。
另请参阅 qHashBits () 和 qHashRangeCommutative ().
Returns the hash value for the range [ first , last ), using seed to seed the calculation, by successively applying qHash () to each element and combining the hash values into a single one.
The return value of this function does not depend on the order of elements in the range. That means that
{0, 1, 2}
and
{1, 2, 0}
hash to the same values. If order matters, for example, for vectors and arrays, use qHashRange () instead. If you are hashing raw memory, use qHashBits ().
Use this function only to implement qHash () for your own custom types. For example, here's how you could implement a qHash () overload for std::unordered_set<int>:
inline uint qHash(const std::unordered_set<int> &key, uint seed = 0) { return qHashRangeCommutative(key.begin(), key.end(), seed); }
It bears repeating that the implementation of qHashRangeCommutative() - like the qHash () overloads offered by Qt - may change at any time. You 不必 rely on the fact that qHashRangeCommutative() will give the same results (for the same inputs) across different Qt versions, even if qHash () for the element type would.
该函数在 Qt 5.5 引入。
另请参阅 qHashBits () 和 qHashRange ().
Sets the global QHash seed to newSeed .
Manually setting the global QHash seed value should be done only for testing and debugging purposes, when deterministic and reproducible behavior on a QHash is needed. We discourage to do it in production code as it can make your application susceptible to algorithmic complexity attacks .
The seed is set in any newly created QHash 。见 qHash about how this seed is being used by QHash .
If the environment variable
QT_HASH_SEED
is set, calling this function will result in a no-op.
Passing the value -1 will reinitialize the global QHash seed to a random value.
该函数在 Qt 5.6 引入。
另请参阅 qGlobalQHashSeed .
写入哈希 hash 到流 out .
This function requires the key and value types to implement
operator<<()
.
另请参阅 序列化 Qt 数据类型 .
读取哈希从流 in into hash .
This function requires the key and value types to implement
operator>>()
.
另请参阅 序列化 Qt 数据类型 .