Firstly, I saw this one , but it doesn’t quite resemble my needs.
I have a situation where I need a sparse array. In some situations where I could, say, 3000 potential entries with only 20 selected, in other situations where I could allocate more or only 3000. Using NSMutableDictionary (with NSString representations of integer index values) would seem to work well for the first case, but, apparently, will be ineffective for the second, both in the field of storage and search speed. Using NSMutableArray with NSNull objects for empty entries will work well enough for the second case, but it seems a bit wasteful (and this can cause annoying delay in the user interface) to insert most of the 3000 NSNull entries for the first case.
The mentioned article mentions the use of NSMapTable, as it supposedly accepts integer keys, but apparently this class is not available on the iPhone (and I'm not sure if I like to have an object that is also not persistent).
So is there any other option?
Added on 9/22
I looked at a custom class that NSMutableSet is built into, with a set of records consisting of a custom class with an integer (for example, the # element) and an element pointer, and written to simulate an NSMutableArray in terms of additions / updates / finds (but does not insert / deletes). This is apparently the most sensible approach.
source
share