Time Complexity of count(for:) in NSCountedSet

I can’t understand what the documentation is saying about this method, count(for:)

from the doc:
"Returns the count associated with a given object in the set.”
also from the doc:
" The count associated with anObject in the set, which can be thought of as the number of occurrences of anObject present in the set.”

is it saying that since Set and NSSet and its subclass NSCountedSet are implemented as HashTable, then accessing the count is done in constant time?

1 Like

Since NSCountedSet is a Foundation type that isn't bridged to a native Swift type like NSSet is to Set, the documentation doesn't make any statement of complexity like the types in the Swift standard library. So there's no guarantee of complexity. But it should be constant time. (In fact, many Foundation collections are class clusters under the hood in Obj-C, so their complexity can vary based on a variety of conditions.)

1 Like