Reputation: 4065
I was wondering how NSMutableArray is working under the hood. Is it dynamic array or some kind of linked list? My question is what is the runtime for:
addObject: //If is array it would be O(N)
insertObjectAtIndex: //Same here
Upvotes: 1
Views: 132
Reputation: 17481
If you're interested in understanding the implementation of NSMutableArray
it is a toll-free bridged version of CFArray
(mutable variant), and the source for CFArray
is actually available from Apple CFArray.c.
The short answer is that it's a pretty complex structure of "buckets" which contain pointers to the elements of the array.
Upvotes: 1