Consider a set of thousands of NSString
objects, in memory.
What is the most efficient way to search for a particular NSString
in the set? Would using NSDictionary
suffice? Or is it guaranteed that NSSet
's search is O(1) (couldn't find any documentation that says so)?
And would the same strategy apply to NSData
objects?
This page shows the following note about sets:
Note: If the objects in the set have a good hash function, accessing an element, setting an element, and removing an element all take constant time. With a poor hash function (one that causes frequent hash collisions), these operations take up to linear time. Classes such as NSString that are part of Foundation have a good hash function.
So for NSString
you could expect constant time based on the above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With