当前位置 : 主页 > 网络编程 > 其它编程 >

为什么dict在这么多操作中遇到最坏情况O(n)

来源:互联网 收集:自由互联 发布时间:2023-07-02
Howexactlyisdictimplementedthatithasalineartimelookupforcollisions?Iwouldassumethat How exactly is dict implemented that it has a linear time lookup for collisions? I would assume that it is implemented as a hashtable backed by a list. I wou
Howexactlyisdictimplementedthatithasalineartimelookupforcollisions?Iwouldassumethat

How exactly is dict implemented that it has a linear time lookup for collisions? I would assume that it is implemented as a hashtable backed by a list. I would presume that a better implementation would be O(log(n)) for various operations, using a tree to back the table instead. Is there some magic happening behind the scenes to keep the constant time lookups alive for as long as possible?

dict究竟是如何实现的,它具有线性时间查找冲突?我认为它是作为由列表支持的哈希表实现的。我认为对于各种操作,更好的实现将是O(log(n)),而使用树来代替表。幕后是否会发生一些魔法,以尽可能长时间地保持恒定的时间查找?

My source for this, by the way, is this:

顺便说一下,我的这个来源是这样的:

http://www.google.com/search?sourceid=chrome it's extremely useful to be able to iterate over [a,b) in an ordered set, which hash tables don't allow.

它们允许有序遍历;能够在有序集中迭代[a,b)非常有用,哈希表不允许这样做。

I do consider it a flaw that Python doesn't have a standard binary tree container, but for the performance characteristics needed by the Python core, like __dict__ lookups, a hash table does make more sense.

我认为Python没有标准的二叉树容器是一个缺陷,但是对于Python核心所需的性能特征,比如__dict__ lookups,散列表确实更有意义。

#5

0

Reliable sources of information about the hash functions and collision-resolution strategy that are actually used include the comments in the source file dictobject.c and the whole of the file dictnotes.txt

关于实际使用的散列函数和冲突解决策略的可靠信息源包括源文件dictobject.c中的注释和整个文件dictnotes.txt

上一篇:什么是3D
下一篇:没有了
网友评论