Dictionary keyed by a few sparse integers?
Dictionary keyed by a few sparse integers?
- Subject: Dictionary keyed by a few sparse integers?
- From: Graham Cox <email@hidden>
- Date: Fri, 29 Oct 2010 22:29:54 +1100
I have a need to associate objects with an arbitrary unsigned integer, which can be pretty much anything. I figured a dictionary with NSNumbers as keys would be perfect, where the NSNumber is created using +numberWithUnsignedInteger:
Trouble is, each time I create the number, it's a new object even if it contains a value NSNumber has seen before, so the lookup fails.
So, I thought I'd just create suitable static NSNumbers, but I have the same problem in another place, since I then need to know which static NSNumbers I've allocated already to a given integer, which means looking them up. While I could just add them to an array and conduct a linear search - for the current situation efficiency isn't likely to be an issue - this solution wouldn't scale very well if it ever needed to.
Is there an obvious alternative I'm overlooking?
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden