标签: swift set time-complexity
Set.indexOf的时间复杂度是多少? documentation没有说,而source代表某种内部存储类(_VariantStorage / _VariantSetStorage),其源代码无法找到。
Set.indexOf
_VariantStorage
_VariantSetStorage
答案 0 :(得分:4)
CollectionType的{{3}}表明它是O(self.count)。
CollectionType
这是有道理的,因为最糟糕的情况是检查Set(或任何其他集合)中的每个元素是否相等。它不应该比O(self.count)复杂更多。
Set