phu
phu

Reputation: 1199

Time complexity of Swift's Set.indexOf

What is the time complexity of Set.indexOf? The documentation doesn't say, and the source delegates to some kind of internal storage class (_VariantStorage/_VariantSetStorage) whose source I can't find.

Upvotes: 2

Views: 1788

Answers (1)

Aaron Rasmussen
Aaron Rasmussen

Reputation: 13316

The documentation for CollectionType suggests that it is O(self.count).

That would make sense, as the worst case scenario is that every element in the Set (or any other collection) is checked for equality. It shouldn't ever be more complex than O(self.count).

Upvotes: 4

Related Questions