I wonder what is the decision behind NSDictionary method allKeys, to return an NSArray, instead of an NSSet, which would make more sense, since there is no guarantee about the order of the returned array and moreover, a key is unique
Well as everybody is guessing...
As the OP said, every key is unique. For either the array or set case the dictionary code has to collect the keys - the cost of that applies to both. In the set case each key has to be added to the set, which involves a (pointless as it turns out) test of membership, while in the array case no membership test is required - the cost of adding to an array should be smaller than adding to a set. Array wins.
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