• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Dictionary keyed by a few sparse integers?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Dictionary keyed by a few sparse integers?
      • From: Alex Kac <email@hidden>
    • Re: Dictionary keyed by a few sparse integers?
      • From: Roland King <email@hidden>
  • Prev by Date: SOAP results doesn't preserve whitespace
  • Next by Date: Re: Dictionary keyed by a few sparse integers?
  • Previous by thread: SOAP results doesn't preserve whitespace
  • Next by thread: Re: Dictionary keyed by a few sparse integers?
  • Index(es):
    • Date
    • Thread