@yngvedh is correct that NSDictionary has an O (1) lookup time (as expected for map structure). However, after some testing, you can see that NSSet also has O (1) search time. Here is the basic test I did to come up with this: http://pastie.org/933070
Basically, I create 1,000,000 lines, and then the time when I need to get 100,000 random from the dictionary and set. When I run this several times, the set really looks faster ...
dict lookup: 0.174897 set lookup: 0.166058 --------------------- dict lookup: 0.171486 set lookup: 0.165325 --------------------- dict lookup: 0.170934 set lookup: 0.164638 --------------------- dict lookup: 0.172619 set lookup: 0.172966
In your particular case, I'm not sure if any of them will be what you want. You say you want all these objects in memory, but do you really need them, or do you just need some of them? If this is the latter, then I would probably read the file and create an object identifier to match the file offset (i.e., I remember where each object identifier is in the file). Then you can see which ones you want and use the file offset to go to the right place in the file, analyze this line and move on. This is a job for NSFileHandle .
Dave delong
source share