Re: Deleting duplicates in NSMutableArray
Re: Deleting duplicates in NSMutableArray
- Subject: Re: Deleting duplicates in NSMutableArray
- From: Allan Odgaard <email@hidden>
- Date: Mon, 5 Jul 2004 03:32:10 +0200
On 5. Jul 2004, at 0:52, King Chung Huang wrote:
I usually just create a new NSSet from my NSArray, then get an array
out of it. Not sure if it's the most efficient way of getting rid of
duplicates, but it's certainly the easiest!
I think the task was to only remove consecutive duplicates, for which
I'd probably use std::unique (or was it?):
NSMutableArray* newArray = [NSMutableArray array];
std::unique_copy(beginof(array), endof(array),
back_inserter(newArray));
This is also more efficient than the code I saw posted here, since the
above is O(n) whereas the other was worst-case O(n^2) because it called
removeObjectAtIndex: (which is O(n)) in the array (which had n
iterations).
But otherwise my money is also on NSSet! :)
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.