• 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
Re: Multidimensiaon Arrays in Cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multidimensiaon Arrays in Cocoa


  • Subject: Re: Multidimensiaon Arrays in Cocoa
  • From: "John C. Randolph" <email@hidden>
  • Date: Sun, 23 Sep 2001 05:52:41 -0700

On Sunday, September 23, 2001, at 04:35 AM, email@hidden wrote:

Am I missing something or are there no multidimensional arrays in Cocoa's NSArray? What do we do, just implement them the old fashioned way with Objective-C?

One trick that just occurred to me for storage of values of a sparse array of any number of dimensions, is to keep the values in an NSDictionary, where the key is the contatenation of the coordinates.

So, if you have a value at (10, 26, 99), and another value at (2, 15, 0), your dictionary would contain:

{
"10:26:99" = <some value>
"2:15:0" = <some other value>
}

And you would use *no* storage for empty or uninitialized values. Your code could treat any value that the dictionary couldn't find as zero or null.

Of course, a hash lookup isn't nearly as fast as multiplying addresses and offsets, but this approach doesn't waste much space.

-jcr


"I fear all we have done is to awaken a sleeping giant and fill him with a terrible resolve." -Admiral Isoroku Yamamoto, Dec 7, 1941.


  • Follow-Ups:
    • Re: Multidimensiaon Arrays in Cocoa
      • From: Ondra Cada <email@hidden>
References: 
 >Multidimensiaon Arrays in Cocoa (From: email@hidden)

  • Prev by Date: Re: Stopping a DO work
  • Next by Date: Re: Multidimensiaon Arrays in Cocoa
  • Previous by thread: Re: Multidimensiaon Arrays in Cocoa
  • Next by thread: Re: Multidimensiaon Arrays in Cocoa
  • Index(es):
    • Date
    • Thread