QHash幫組文檔中文版_第1頁
QHash幫組文檔中文版_第2頁
QHash幫組文檔中文版_第3頁
QHash幫組文檔中文版_第4頁
QHash幫組文檔中文版_第5頁
已閱讀5頁,還剩40頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、QHash幫組文檔中文翻譯版Qt 5.13Qt CoreC+ ClasseQHashQt 5.13.0 Reference DocumentationContents (目錄)?Public Types (公共類型)?Public Functions (公共函數(shù))?Related Non-Members (相關(guān)非成員)?Detailed Description (詳細說明)? The qHash() hashing function (qHash () 哈希函數(shù))?AlgoAthmic complexity attacks (算法復雜性攻擊)QHash Class (QHash 類)The Q

2、Hashclass is a template class that provides a hash-table-based dictionary.More. (QHash類是提供基于哈希表的字典的模板類。更多。)Header: #include *QHashqmake: QT += coreInherited By: QMultiHash? List of all members, including inherited members (所有成員(包括繼承成員)的列表)Note: All functions in this class arereentrant.(注意:這個類中的所有函數(shù)都

3、是 可重入的。)Public Types (公共類型)classconst iteratorclassiteratorclasskey iteratortypedef ConstIteratortypedef Iteratortypedef const key valuejteratortypedef difference typetypedef key_typetypedef key_valuejteratortypedef mapped_typetypedef size_typePublic Functions(公共函數(shù))QHash(QHaskK, V &other) QHash(cons

4、t QHash Mother) QHash(std二initializer_liststd:pair list) QHash()QHash &operator= (QHash &other)QHash &operator= (const QHash &other) QHash()QHash:iterator begin() QHash:constJterator begin() const int capacity () const QHash:constJterator cbegin() const QHash:constJterator cend() constvoid clear()QH

5、ash:constJterator constBegin() constQHash:constJterator constEnd() constQHash:constJterator constFind(const Key &key) const QHash:const_key_valueJterator constKeyValueBegin() const QHash:const_key_valueJterator constKeyValueEndQ const bool contains(const Key &key) const int count(const Key &key) con

6、st int count () constbool empty () constQHash:iterator end()QHash:constJterator end() constQPair equal range(const Key &key)equal range(const Key &key) constQPairQHash:iterator erase(QHashi:const_iterator poQHash:iterator erase(QHash:iterator pos)QHash:iterator find (const Key &key)QHash:constJterat

7、or find (const Key &key) constQHash:iterator insert(const Key &key, const T &/alue)QHash:iterator insertMulti (const Key &key, const T &value)bool isEimppty() constconst Keykey(const T &value) const const Keykey(const T &value, const Key &defaultKey)constQHashL:key_iterator keyBegin() const QHash:ke

8、y_iterator keyEnd() const QHash:key_valueJterator keyValueBegin() QHash:const_key_valueJterator keyValueBegin() const QHash:key_valueJterator keyValueEnd() QHash:const_key_valueJterator keyValueEnd() const QListKey*eys() const QListKey*eys(const T &value) const int remove(const Key &key) void reserv

9、e(int siz int size() const void squeeze() void swap(QHash &)ther) Ttake(const Key &key) QListuniqueKeys() constQHash &unite (const QHash &other) const Tvalue(const Key &key) const const Tvalue(const Key &key, const T &defaultValue) constQListvalues() constQListvalues(const Key &key) const,operator!=

10、 (const QHaslrK, V &other)bool .constoperator=(const QHash &other)bool.constT &operator (const Key &key) const Toperator口 (const Key &key) constRelated Non-Members (相關(guān)非成員)int qGlobalQHashSeedQuint qHash(const QSslDiffieHellmanParameters &hparam, uint seed) uint qHash(char key, uint seed =)uint qHash

11、(const QUrl &url, uint seed = 0)uint qHash(const QOcspResponse Response uint seed)uint qHash(const QSet &ey, uint seed =)uint qHash(const QHash &ey, uint seed =) uint qHash(const QBitArray &key, uint seed =)uint qHash(uchar key, uint seed =.)uint qHash(QSslEllipticCurvecurve, uint seed)uint qHash(QL

12、atin1String key, uint seed =.)uint qHash(signed charkey, uint seed =.)uint qHash(ushort key, uint seed =.)uint qHash(const T *key, uint seed =.)uint qHash(short key, uint seed =.)uint qHash(const QDateTime &key, uint seed =.)uint qHash(uint key, uint seed =.)uint qHash(const QDate &key, uint seed =.

13、)uint qHash(int key, uint seed =.)uint qHash(const QPair &ey, uint seed =.)uint qHash(const QTime &key, uint seed =.)uint qHash(ulong key, uint seed =.)uint qHash(const std二pair &key, uint seed =.)uint qHash(const QVersionNumber &key, uint seed = 0) uint qHash(long key, uint seed =.)uint qHash(quint

14、64 key, uint seed =.)uint qHash(qint64 key, uint seed =.) uint qHash(float key, uint seed = 0)uint qHash(double key, uint seed = 0)uint qHash(long double key, uint seed = 0)uint qHash(const QCharkey, uint seed =.)uint qHash(const QByteArray &key, uint seed =.)uint qHash(const QString &key, uint seed

15、 =.)uint qHash(const QStringRef &ey, uint seed =.)uint qHashBits(const void *p, size_tlen, uint seed =.)uint qHashRange(InputIterator first, InputIterator last, uint seed =.)uintqHashRangeCommutative(InputIterator first, InputIterator last, uintseed =.)void qSetGlobalQHashSeec(int newSee。QDataStream

16、&operator (QDataStream &out, const QHash &iash)QDataStream&operator(QDataStream &in, QHash &ash)Detailed Description (詳細說明)QHash is one of Qts genericontainer classes It stores (key, value) pairs and provides very fast lookup of the value associated with a key.譯:QHash是Qt的通用容器類之一。它存儲(鍵、值)對,并提供與 鍵關(guān)聯(lián)的值

17、的快速查找。QHash provides very similar functionality to QMap. The differences are:譯:QHashl供了與QMaHE常相似的功能。區(qū)別在于:? QHash provides faster lookups than QMap. (See Algorithmic Complexity for details.)譯:QHashfS供比QMapS快的查找。(有關(guān)詳細信息,請參見算法復雜性。)? When iterating over a QMap, the items are always sorted by key. With Q

18、Hash, the items are arbitrarily ordered.譯:在QMa葉迭代時,項始終按鍵排序。使用 QHash項是任意排序的。? The key type of a QMap must provide operator(). The key type of a QHash must provide operator=() and a global hash function called qHash() (see qHash).譯:QMap勺鍵key類型必須提供運算符 ()。QHash的鍵類型必須提供運算 符=()和名為QHash()的全局哈希函數(shù)(請參見 QHash

19、。Heres an exampleQHashwith QString keys andint values:譯:下面是一個帶有 QString鍵和int值的QHashS例:QHash hash;To insert a (key, value) pair into the hash, you can use operator():譯:要將(鍵、值)對插入哈希,可以使用運算符口 ():hashone = 1;hashthree = 3;hashseven = 7;This inserts the following three (key, value) pairs into the QHash (

20、one, 1), (three, 3), and (seven, 7). Another way to insert items into the hash is to use insert ():譯:這會將以下三對(鍵、值)插入 QHash: (“一”,1)、(“三”,3)和(“七”,7) o將項插入哈希的另一種方法是使用insert ():hash.insert(twelve, 12);To look up a value, use operator() or value():譯:要查找值,請使用運算符口 (0)或value ():int numl = hashthirteen;int n

21、um2 = hash.value(thirteen);If there is no item with the specified key in the hash, these functions return a default-constructed value.譯:如果哈希中沒有具有指定鍵的項,則這些函數(shù)將返回默認的構(gòu)造值。If you want to check whether the hash contains a particular key, usecontains():譯:如果要檢查哈希是否包含特定密鑰,請使用 contains ():int timeout = 30;if (

22、hash.contains(TIMEOUT)timeout = hash.value(TIMEOUT);There is also avalue() overload that uses its second argument as a default value if there is no item with the specified key:譯:如果沒有具有指定鍵的項,則還有一個value ()重載將其第二個參數(shù)用作默認值:int timeout = hash.value(TIMEOUT, 30);In general, we recommend that you use contai

23、ns() and 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:譯:通常,我們建議您使用 contains

24、()和value ()而不是operator口()來查找哈希中的鍵。原因是,如果不存在具有相同密鑰的項(除非哈希為 const),則運算符口 ()會靜默地將項插入哈希中。例如,以下代碼段將在 內(nèi)存中創(chuàng)建1000個項:/ WRONG 錯誤QHash hash;.for (int i = 0; i 1000; +i) if (hashi = okButton) cout Found button at index i using a Java-style iterator:譯:如果要瀏覽QHash中存儲的所有(鍵、值)Xt可以使用迭代器。QHash提供 Java 風格的迭代器(QHash iter

25、ator 和 QMutableHashIterator )和 STL 風格的迭代器(QHash : const_迭代器和QHash :迭代器)。下面是如何 使用Java風格的迭代器在QHash上迭代:QHashIterator i(hash);while (i.hasNext() i.next();cout i.key() : i.value() endl;Heres the same code, but using an STL-style iterator:譯:下面是相同的代碼,但是使用了STL風格的迭代器:QHash:const_iterator i = hash.constBegin(

26、);while (i != hash.constEnd() cout i.key() : i.value() endl; +i;QHash is unordered, so an iterators sequence cannot be assumed to be predictable. If ordering by key is required, use aQMap.譯:QHash無序的,因此不能假定迭代器的序列是可預測的。如果需要按鍵 排序,請使用QMapNormally, a QHashallows only one value per key. If you calinsert()

27、 with a key that already exists in the QHash, the previous value is erased. For example:譯:通常,QHash只允許每個鍵有一個值。如果使用QHash中已存在的鍵調(diào)用insert (),則會刪除上一個值。例如:hash.insert(plenty, 100);hash.insert(plenty, 2000);/ hash.value(plenty) = 2000However, you can store multiple values per key by usingpnsertMulti () inst

28、ead of insert () (or using the convenience subclasQMultiHash). If you want to retrieve all the values for a single key, you can use values(const Key &key), which returns a QList:譯:但是,通過使用insertMulti ()而不是insert ()(或使用便利子類 QMultiHash),可以為每個鍵存儲多個值。如果要檢索單個鍵的所有值,可以 使用值(const key&key ),它返回一個 QList :QList

29、 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 ther

30、e:譯:共享同一密鑰的項可以從最近插入到最近插入。一種更有效的方法是調(diào)用 find ()來獲取帶有鍵的第一個項的迭代器并從中進行迭代:QHash: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:譯:如果只需要從散列(而不是鍵)中提取值,還可以使用foreach :QHas

31、h hash;.foreach (int value, hash) cout value endl;Items can be removed from the hash in several ways. One way is to ca!lemove(); 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().譯:可以通過多種方式從散列中移

32、除項。一種方法是調(diào)用remove ();這將刪除具有給定密鑰的任何項。另一種方法是使用 QMutableHashIterator : remove ()。止匕外,還可以使用clear ()清除整個散列。QHashs key and value data types must beassignable data types You cannot, for example, store a QWidget as a value; instead, store aQWidget *.譯:QHash的鍵和值數(shù)據(jù)類型必須是可分配的數(shù)據(jù)類型。例如,您不能將QWidget存儲為值;而是存儲 QWidget*

33、。The qHash() hashing function (qHash ()哈希函數(shù))A QHashs 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 types namespace that returns a hash value for an argument of the keys type.譯:QHash的密鑰類型除了是

34、可分配的數(shù)據(jù)類型外,還具有其他要求:它必須 提供operator=(),并且該類型的命名空間中還必須有QHash()函數(shù),該函數(shù)返回該密鑰類型的參數(shù)的哈希值。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, then qHash(e1) = qHash

35、(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.譯:函數(shù)的作用是:根據(jù)鍵計算一個數(shù)值。它可以使用任何可以想象的算法, 只要給定相同的參數(shù),它總是返回相同的值。換句話說,如果 e1=e2,那么 qHash(e1) =qHash(e2)也必須保持不變。但是,為了獲得良好的性能,qHash ()

36、函數(shù)應該盡量為不同的鍵返回不同的哈希值。For a key typeK, the qHash function must have one of these signatures:譯:對于密鑰類型K, qHash函數(shù)必須具有以下簽名之一:uintqHash (K key);uintqHash (const K &key);uintqHash (K key, uintseed);uint qHash (const K &key,uint seed);The two-arguments overloads take an unsigned integer that should be used t

37、o seed the calculation of the hash function. This seed is provided byQHash 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 byQHash (note that you can simply define a two-arguments versi

38、on, and use a default value for the seed parameter).譯:兩個參數(shù)重載采用一個無符號整數(shù),該整數(shù)應用于為哈希函數(shù)的計算設(shè)定 種子。此種子由QHas譙供,以防止一系列算法復雜性攻擊。如果為鍵類型定 義了一個參數(shù)和兩個參數(shù)重載,QHashh等使用后者(請注意,您可以簡單地定 義兩個參數(shù)版本,并為seed參數(shù)使用默認值)oHeres a partial list of the C+ and Qt types that can serve as keys in QHash any integer type (char, unsigned long, e

39、tc.), any pointer type, QChar QString, and QByteArray. For all of these, the header defines aqHash() function that computes an adequate hash value. Many other Qt classes also declare qHash overload for their type; please refer to the documentation of each class.譯:下面是C+神口 QT類型的部分列表,這些類型可以作為 QHAS用的關(guān)鍵字

40、: 任何整數(shù)類型(char、un簽署10ng等)、任何指針類型、QChar qStand和 qBytErRay.對于所有這些,頭定義了一個 QHash ()函數(shù),該函數(shù)計算足夠的 散列值。許多其他Qt類也為其類型聲明qHash重載;請參閱每個類的文檔。If you want to use other types as the key, make sure that you provide operator=() and a qHash() implementation.譯:如果要使用其他類型作為鍵,請確保提供operator=)和qHash ()實現(xiàn)。Example:(例子)#ifndef E

41、MPLOYEE#define EMPLOYEEclass Employeepublic:Employee() Employee(const QString &name, const QDate &dateOfBirth);private:QString myName;QDate myDateOfBirth;);inline bool operator=(const Employee &e1, const Employee &e2)(return () = ()& e1.dateOfBirth()= e2.dateOfBirth();)inline uint qHash (const Emplo

42、yee &key, uint seed)(return qHash (), seed) A key.dateOfBirth().day();)#endif / EMPLOYEEIn the example above, weve relied on Qts globalqHash(const QString &, uint) to give us a hash value for the employees name, and XORed this with the day they were born to help produce unique hashes for people with

43、 the same name.譯:在上面的示例中,我們依賴于 Qt的全局qHash (const QString& , uint ) 為員工的姓名提供一個散列值,并在員工出生時將其與之進行異或,以幫助為 同名員工生成唯一的散列。Note that the implementation of the qHash() overloads offered by Qt may change at any time. You must not rely on the fact that qHash() will give the same results (for the same inputs) ac

44、ross different Qt versions.譯:注意,Qt提供的qHash ()重載的實現(xiàn)可能隨時更改。您不能依賴這樣一 個事實:qHash()將在不同的Qt版本中提供相同的結(jié)果(對于相同的輸入)。Algorithmic complexity attacks(算法復雜性攻擊)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

45、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), seeAlgorithmic Complexity for the details) when the data is fed into the table.譯:所有哈希表都容易受到特定類別的拒絕服務攻擊,在這

46、種攻擊中,攻擊者 會小心地預先計算一組不同的密鑰,這些密鑰將被散列到哈希表的同一個存儲桶中(甚至具有相同的散列值)0攻擊的目的是在將數(shù)據(jù)輸入到表中時獲得最 壞情況下的算法行為(O (n),而不是攤銷的O (1),詳細信息請參見算法 復雜性。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 attacks extent. This seed is automa

47、tically generated byQHash once per process, and then passed by QHash as the second argument of the two-arguments overload of the qHash() function.譯:為了避免這種最壞的行為,qHash()完成的散列值的計算可以通過隨機 種子進行轉(zhuǎn)換,從而使攻擊的范圍無效。此種子在每個進程中由QHash自動生 成一次,然后作為QHash()函數(shù)的兩個參數(shù)重載的第二個參數(shù)由QHash專遞。This randomization of QHash is enabled by

48、 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 to have the value

49、0. Alternatively, you can call the qSetGlobalQHashSee function with the value 0.譯:默認情況下,QHash的這種隨機化是啟用的。即使程序永遠不應該依賴于 特定的QHash順序,也可能存在暫時需要確定性行為的情況,例如調(diào)試或回歸 測試。要禁用隨機化,請將環(huán)境變量QT_HASH_SEEDC為值0?;蛘?,可以使用值 0 調(diào)用 qSetGlobalQHashSeed ()函數(shù)。See alsoQHashIterator, QMutableHashIterator, QMap, and QSet譯:另請參見 QHashIte

50、rator、QMutableHashIterator QMap 和 QSet。Member Type Documentation(成員類型文檔)typedef QHash:ConstIterator/ (模板類型,常迭代器實現(xiàn))Qt-style synonym for QHash二const_計erator.typedef QHash:Iterator (模板類型,迭代器實現(xiàn))Qt-style synonym for QHash:iterator.typedef QHash:const_key_value_iterator/ (模板類型,常 _鍵_值_迭代器實現(xiàn))The QMap二const

51、key value Aerator typedef provides an STL-style const iterator for QHash and QMultiHash.譯:QMap : const_key_value_iterator typedef為 QHash口 QMultiHash 提供STL樣式的const迭代器。QHash:const_key_value_iterator is essentially the same aQHash二constjterator with the difference that operator*() returns a key/value p

52、air instead of a value.譯:QHash : const_key_value_迭代器本質(zhì)上與 QHash : const_迭代器相 同,區(qū)別在于運算符* ()返回位/值對而不是值。This typedef was introduced in Qt 5.10.譯:這個類型定義是在 Qt 5.10中引入的。See alsoQKeyValueIterator.譯:另請參見 QKeyValueIterator 。typedef QHash:difference_type/ (類型定義 QHash::差異類型)Typedef for ptrdiff_t. Provided for S

53、TL compatibility.譯:ptrdiff_t的類型定義.為STL提供兼容性。typedef QHash:key_type/ (類型定義 QHash:鍵類型)Typedef for Key. Provided for STL compatibility.譯:鍵key的類型定義.為STL提供兼容性。typedef QHash:key_valueterator (類型定義 QHash::鍵值迭代器)The QMap二key valuejterator typedef provides an STL-style iterator forQHash and QMultiHash.譯:鍵值迭代

54、器類型定義為 QHashffi QMultiHash提供了一個STL風格的迭代 器。QHash:key_value_iterator is essentially the same aQHash二iterator with the difference that operator*() returns a key/value pair instead of a value.譯:QHash : key_value_迭代器本質(zhì)上與QHash :迭代器相同,區(qū)別在于 運算符* ()返回鍵/值對而不是值。This typedef was introduced in Qt 5.10.譯:這個typede

55、f是在Qt 5.10中引入的See alsoQKeyValuelterator.譯:另請參見 QKeyValueIterator 。typedef QHash:mapped_type/ (類型定義 QHash: : Ma_類型)Typedef for T. Provided for STL compatibility.譯:T的類型定義.為STL供兼容性typedef QHash:size_type(類型定義 QHash:大小 _類型)Typedef for int. Provided for STL compatibility.譯:整形的類型定義.為STL提供兼容性Member Functio

56、n Documentation(成員函數(shù)文檔)QHash:QHash(QHash &other)Move-constructs a QHashinstance, making it point at the same object that other was pointing to.譯:Move構(gòu)造一個QHash實例,使它指向另一個所指向的對象。This function was introduced in Qt 5.2.譯:Qt 5.2中引入了此功能。QHash:QHash(const QHash &other)Constructs a copy ofother.譯:構(gòu)造其他的副本。Thi

57、s operation occurs in constant time, becauseQHash is implicitly shared. 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 linear time.譯:此操作在固定時間內(nèi)發(fā)生,因為QHash是隱式共享的。這使得從函數(shù)返回QHash非???。如果修改了共享實例,它將被復制(寫時復制),這需要 線性時間。

58、See alsooperator=().譯:另請參見運算符=()QHash:QHash(std:initializer_liststd:pair list)Constructs a hash with a copy of each of the elements in the initializer listlist.This function is only available if the program is being compiled in C+11 mode.This function was introduced in Qt 5.1.譯:構(gòu)造一個哈希,其中包含初始值設(shè)定項列表中每

59、個元素的副本。此功能僅在程序以C+ 11模式編譯時才可用。Qt 5.1中引入了此功能。QHash:QHash()Constructs an empty hash.譯:構(gòu)造空哈希。See alsoclear().譯:另請參見clear ()。QHash &QHash:operator=(QHash &other)Move-assignsother to this QHashinstance.譯:Move將另一個分配給此QHash實例。This function was introduced in Qt 5.2.譯:Qt 5.2中引入了此功能。QHash &QHash:operator=(cons

60、t QHash &other)Assignsother to this hash and returns a reference to this hash.譯:將其他項分配給此哈希并返回對此哈希的引用。QHash:QHash()Destroys the hash. References to the values in the hash and all iterators of this hash become invalid.譯:銷毀散列。對哈希中的信和此哈希的所有迭代器的引用都將無效。QHash:iterator QHash:begin()Returns an STL-style iter

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論