Reputation: 38213
I am trying to implement something similar to the flight control game. There will be a set of objects representing planes that get spawned and removed 'randomly'. Individual planes can then get touched and will respond. The model should take a plane index as a parameter when something get touched.
My storage requirements are:
Need to look up and item quickly by index
NSMutableArray
, NSMutableSet
?Upvotes: 0
Views: 102
Reputation: 13461
NSMutableArray
is good enough if you want to look up only by index. The problem may be the deletion which takes O(n). When you do not need the index persistence you may delete in O(1) by placing the last item to the item deleted and shorten the array by 1.
Storing at two places would be slow in this case, because it would not bring any advantage in searching speed, but would require to maintain two containers.
Upvotes: 1
Reputation: 15357
Storing in 2 places seems silly. An Array should be fine, with o(n) iteration, o(1) look up by index. I am not familiar with objective-c to know the deletion or insertion speed, but both should be plenty fast if some system level array copy facilities are used.
Upvotes: 0