Swift的Set.indexOf的时间复杂度

时间:2016-03-24 22:58:44

标签: swift set time-complexity

Set.indexOf的时间复杂度是多少? documentation没有说,而source代表某种内部存储类(_VariantStorage / _VariantSetStorage),其源代码无法找到。

1 个答案:

答案 0 :(得分:4)

CollectionType的{​​{3}}表明它是O(self.count)。

这是有道理的,因为最糟糕的情况是检查Set(或任何其他集合)中的每个元素是否相等。它不应该比O(self.count)复杂更多