简体   繁体   English

QMap是hash表吗?

[英]Is QMap a hash table?

I used Qmap many times but perhaps never used QHash .我多次使用 Qmap 但也许从未使用过 QHash Now I'm reading about hash tables.现在我正在阅读 hash 表。

Is QMap a hash table? QMap是hash表吗?

I presume down there in a QHash we will find the ideas of Hash Maps .我假设在 QHash 中我们会找到Hash Maps的想法。 Should I say QHash is the implementation of a hash map (or hash table) data structure?我应该说QHash是一个hash map(或hash表)数据结构的实现吗? Is QMap also the implementation of a hash table? QMap也是hash表的实现吗?

No QMap is not a hash table.没有 QMap 不是 hash 表。 Per the documentation:根据文档:

The QMap class is a template class that provides a red-black-tree-based dictionary. QMap class 是一个模板 class ,它提供了一个基于红黑树的字典。

In other words it is a binary sort tree that uses the red-black tree algorithm to maintain balance.换句话说它是一棵使用红黑树算法来保持平衡的二叉排序树。 Meaning that searches will take O(logN) rather than O(1) as in the case of QHash.这意味着搜索将采用 O(logN) 而不是像 QHash 那样的 O(1)。

It also means that QMap will keep the data sorted.这也意味着 QMap 将保持数据排序。

From the documentation you quoted:从您引用的文档中:

QMap and QHash provide very similar functionality. QMap 和 QHash 提供非常相似的功能。 The differences are:不同之处在于:

  • QHash provides average faster lookups than QMap. QHash 提供比 QMap 平均更快的查找。 (See Algorithmic Complexity for details.) (有关详细信息,请参阅算法复杂性。)
  • When iterating over a QHash, the items are arbitrarily ordered.当遍历 QHash 时,项目是任意排序的。 With QMap, the items are always sorted by key.使用 QMap,项目总是按键排序。
  • The key type of a QHash must provide operator==() and a global qHash(Key) function. The key type of a QMap must provide operator<() specifying a total order. QHash 的键类型必须提供 operator==() 和全局 qHash(Key) function。QMap 的键类型必须提供 operator<() 指定总顺序。 Since Qt 5.8.1 it is also safe to use a pointer type as key, even if the underlying operator<() does not provide a total order.从 Qt 5.8.1 开始,使用指针类型作为键也是安全的,即使底层 operator<() 不提供全序。

QHash is a hash table. QHash 是一张 hash 的表。 QMap is a binary sort tree using the red black tree algorithm. QMap是使用红黑树算法的二叉排序树。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM