Re: multidimensional arrays
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