Re: NSMutableArray fill with unique values from NSArray
Re: NSMutableArray fill with unique values from NSArray
- Subject: Re: NSMutableArray fill with unique values from NSArray
- From: Mike Abdullah <email@hidden>
- Date: Thu, 20 Aug 2009 13:54:39 +0100
On 20 Aug 2009, at 13:43, Devraj Mukherjee wrote:
Hi all,
I have NSMutableArray (fixed length) that I wish to fill with unique
values at each index from a source NSArray (fixed length, greater than
the length of the target mutable array).
This sounds worrying. There is no such thing as a fixes length mutable
array unless you specifically create your own subclass to behave like
this. I think you're confusing what -initWithCapacity: and friends
really do.
Realise that I can do this by writing a loop and check to see if a
value has bee pre-filled, the last indexes take a while to fill (for
obvious reasons of randomisation).
Is there are better way of doing this?
Does the ordering of the objects in the final array actually matter?
If so, looping through each object and checking for -containsObject:
is your best approach. If ordering is not important then you shouldn't
be using an array anyway; instead use NSMutableSet which is designed
for this sort of thing. Possibly if testing shows this to be a
performance bottleneck you could use both NSMutableArray and
NSMutableSet together, one to store the ordered objects, one to
quickly check if an object is already present.
--
"The secret impresses no-one, the trick you use it for is everything"
- Alfred Borden (The Prestiege)
_______________________________________________
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
_______________________________________________
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