QHash帮组文档中文版_第1页
QHash帮组文档中文版_第2页
QHash帮组文档中文版_第3页
QHash帮组文档中文版_第4页
QHash帮组文档中文版_第5页
已阅读5页,还剩40页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、QHash帮组文档中文翻译版Qt 5.13Qt CoreC+ ClasseQHashQt 5.13.0 Reference DocumentationContents (目录)?Public Types (公共类型)?Public Functions (公共函数)?Related Non-Members (相关非成员)?Detailed Description (详细说明)? The qHash() hashing function (qHash () 哈希函数)?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.(注意:这个类中的所有函数都

3、是 可重入的。)Public Types (公共类型)classconst iteratorclassiteratorclasskey iteratortypedef ConstIteratortypedef Iteratortypedef const key valuejteratortypedef difference typetypedef key_typetypedef key_valuejteratortypedef mapped_typetypedef size_typePublic Functions(公共函数)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 (相关非成员)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的通用容器类之一。它存储(键、值)对,并提供与 键关联的值

17、的快速查找。QHash provides very similar functionality to QMap. The differences are:译:QHashl供了与QMaHE常相似的功能。区别在于:? QHash provides faster lookups than QMap. (See Algorithmic Complexity for details.)译:QHashfS供比QMapS快的查找。(有关详细信息,请参见算法复杂性。)? 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()的全局哈希函数(请参见 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.译:如果哈希中没有具有指定键的项,则这些函数将返回默认的构造值。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 ()重载将其第二个参数用作默认值: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),则运算符口 ()会静默地将项插入哈希中。例如,以下代码段将在 内存中创建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中已存在的键调用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:译:共享同一密钥的项可以从最近插入到最近插入。一种更有效的方法是调用 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、除项。一种方法是调用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的键和值数据类型必须是可分配的数据类型。例如,您不能将QWidget存储为值;而是存储 QWidget*

33、。The qHash() hashing function (qHash ()哈希函数)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、可分配的数据类型外,还具有其他要求:它必须 提供operator=(),并且该类型的命名空间中还必须有QHash()函数,该函数返回该密钥类型的参数的哈希值。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.译:函数的作用是:根据键计算一个数值。它可以使用任何可以想象的算法, 只要给定相同的参数,它总是返回相同的值。换句话说,如果 e1=e2,那么 qHash(e1) =qHash(e2)也必须保持不变。但是,为了获得良好的性能,qHash ()

36、函数应该尽量为不同的键返回不同的哈希值。For a key typeK, the qHash function must have one of these signatures:译:对于密钥类型K, qHash函数必须具有以下签名之一: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).译:两个参数重载采用一个无符号整数,该整数应用于为哈希函数的计算设定 种子。此种子由QHas谯供,以防止一系列算法复杂性攻击。如果为键类型定 义了一个参数和两个参数重载,QHashh等使用后者(请注意,您可以简单地定 义两个参数版本,并为seed参数使用默认值)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用的关键字

40、: 任何整数类型(char、un签署10ng等)、任何指针类型、QChar qStand和 qBytErRay.对于所有这些,头定义了一个 QHash ()函数,该函数计算足够的 散列值。许多其他Qt类也为其类型声明qHash重载;请参阅每个类的文档。If you want to use other types as the key, make sure that you provide operator=() and a qHash() implementation.译:如果要使用其他类型作为键,请确保提供operator=)和qHash ()实现。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 ()重载的实现可能随时更改。您不能依赖这样一 个事实:qHash()将在不同的Qt版本中提供相同的结果(对于相同的输入)。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攻击的目的是在将数据输入到表中时获得最 坏情况下的算法行为(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()完成的散列值的计算可以通过随机 种子进行转换,从而使攻击的范围无效。此种子在每个进程中由QHash自动生 成一次,然后作为QHash()函数的两个参数重载的第二个参数由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顺序,也可能存在暂时需要确定性行为的情况,例如调试或回归 测试。要禁用随机化,请将环境变量QT_HASH_SEEDC为值0。或者,可以使用值 0 调用 qSetGlobalQHashSeed ()函数。See alsoQHashIterator, QMutableHashIterator, QMap, and QSet译:另请参见 QHashIte

50、rator、QMutableHashIterator QMap 和 QSet。Member Type Documentation(成员类型文档)typedef QHash:ConstIterator/ (模板类型,常迭代器实现)Qt-style synonym for QHash二const_计erator.typedef QHash:Iterator (模板类型,迭代器实现)Qt-style synonym for QHash:iterator.typedef QHash:const_key_value_iterator/ (模板类型,常 _键_值_迭代器实现)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_迭代器本质上与 QHash : const_迭代器相 同,区别在于运算符* ()返回位/值对而不是值。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_迭代器本质上与QHash :迭代器相同,区别在于 运算符* ()返回键/值对而不是值。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(成员函数文档)QHash:QHash(QHash &other)Move-constructs a QHashinstance, making it point at the same object that other was pointing to.译:Move构造一个QHash实例,使它指向另一个所指向的对象。This function was introduced in Qt 5.2.译:Qt 5.2中引入了此功能。QHash:QHash(const QHash &other)Constructs a copy ofother.译:构造其他的副本。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.译:此操作在固定时间内发生,因为QHash是隐式共享的。这使得从函数返回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.译:构造一个哈希,其中包含初始值设定项列表中每

59、个元素的副本。此功能仅在程序以C+ 11模式编译时才可用。Qt 5.1中引入了此功能。QHash:QHash()Constructs an empty hash.译:构造空哈希。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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论