• 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: multidimensional arrays
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: multidimensional arrays


  • Subject: Re: multidimensional arrays
  • From: Andy Armstrong <email@hidden>
  • Date: Mon, 14 Mar 2005 12:34:05 +0000

On 14 Mar 2005, at 12:28, Thomas Davie wrote:
I've run into a situation where it would be great to have a multidimensional NSArray or NSMutableArray. Is there such a class? If not, any suggestions on the most elegant solution?
Why not just implement them as they are in 99.9% of other langauges/frameworks - an array of arrays.

Actually quite a few languages implement them as a single array of size rows * cols and do the necessary arithmetic on the index to hit the right slot. That's an approach that would work with NSArrays too.


In general (and in psuedocode)

int x[cols, rows]    ==>   int x[cols * rows]

x[c, r] = n          ==>   x[c * rows + r] = n

I'd assume, without having given it too much thought, that a category could be added to NS(Mutable)Array to do the same.

--
Andy Armstrong, hexten.net

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: multidimensional arrays
      • From: j o a r <email@hidden>
References: 
 >multidimensional arrays (From: Daniel Child <email@hidden>)
 >Re: multidimensional arrays (From: Thomas Davie <email@hidden>)

  • Prev by Date: Re: multidimensional arrays
  • Next by Date: Re: multidimensional arrays
  • Previous by thread: Re: multidimensional arrays
  • Next by thread: Re: multidimensional arrays
  • Index(es):
    • Date
    • Thread