On Mar 15, 2009, at 7:33 PM, Oleg Krupnov wrote:

I need to use a dictionary inside a long, time-consuming operation.
The keys of the dictionary are integers, the values are NSObjects.

I could use NSDictionary, but I don't like the overhead of creating
NSNumbers for the keys and then comparing them, where I could use
integers directly more efficiently, both by time and memory.

The question is: is there this kind of fast int-keyed dictionary in
Cocoa or elsewhere? Thanks!
_______________________________________________

You can write your implementation file in Objective C++ , and use std::map<int,id>
Then write your header like this:
#ifdef __cplusplus
#include <map>
#endif

@interface MyClass: NSObject
{
#ifdef __cplusplus
        std::map<int,id> * mymap; //All data pointers have same size,
#else
        void *   mymap;
#endif
}

@end

Then in your implementation file initialize your pointer:
mymap = new std::map<int,id>

and use it like this:
(*mymap) [integervalue] = someid;


-----------------------------------
See the amazing new SF reel: Invasion of the man eating cucumbers from outer space. On congratulations for a fantastic parody, the producer replies : "What parody?"

Tommy Nordgren
tommy.nordg...@comhem.se



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to