Swift 集合包含复杂性

Har*_*ris 8 time-complexity data-structures swift

集合有 contains 函数,如果集合中存在成员,则返回 true;否则为假。

其复杂度为O(1)。

我想知道它的复杂度如何是恒定的 O(1) 即它不依赖于大小

以下是文档:https://developer.apple.com/documentation/swift/set/1540013-contains

Rav*_*dav 5

它将使用哈希函数来插入、搜索。好的哈希函数会导致时间复杂度为0(1)。 https://en.wikipedia.org/wiki/Hash_table