简体   繁体   English

OrderedSet() 是否还有 O(1) 的搜索参数?

[英]Does OrderedSet() still have a search parameter of O(1)?

I have heard that when you perform an in operator on a list it has to search through O(n) objects while if you do it on a set it has to search through O(1) objects.我听说当您在列表上执行in运算符时,它必须搜索 O(n) 个对象,而如果您在一个集合上执行此操作,则必须搜索 O(1) 个对象。 To see what I mean go here .这里了解我的意思 go 。 Does this still apply to OrderedSet ?这仍然适用于OrderedSet吗?

Which OrderedSet are you talking about?你在说哪个OrderedSet At this time (Python 3.8.3), there is not OrderedSet in the standard library.此时(Python 3.8.3),标准库中没有OrderedSet

Typically , OrderedSet implementations will implement __contains__ by delegating to the underlying set .通常,OrderedSet 实现将通过委托给底层set来实现__contains__ So it will have the algorithmic complexity you would expect.因此,它将具有您所期望的算法复杂性。

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

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