Re: Removing duplicates from NSMutableArray
Re: Removing duplicates from NSMutableArray
- Subject: Re: Removing duplicates from NSMutableArray
- From: Jeff Disher <email@hidden>
- Date: Mon, 2 Dec 2002 20:43:21 -0500
Since the array has to be sorted, you can take advantage of that. Most
algorithms will be theta(n^2) time but if the array is already sorted
then you can do it in theta(n) time.
Here is the pseudo-code for an algorithm to do that:
duplicate = source[0];
for x = 1 -> [source count]
{
if (duplicate != source[x])
{
duplicate = source[x];
[destination add:duplicate]
}
}
I think that would work. At least you get the idea of what I am
saying. Since it is sorted, you know that duplicates will always be
grouped.
Hope that helps,
Jeff.
On Monday, December 2, 2002, at 06:43 PM, Jan Van Tol wrote:
On Monday, December 2, 2002, at 04:47 PM, Sherm Pendley wrote:
On Monday, December 2, 2002, at 05:05 PM, Jan Van Tol wrote:
What is the best way to filter out duplicate NSStrings from an
NSMutableArray?
Traditional Perl wisdom is that, whenever you find yourself using the
words "unique" or "duplicate," you should be thinking about a hash
instead of an array. In Objective-C terms, that would be an
NSDictionary instead of an NSArray. That is, when you're building the
list, instead of doing this:
Except that I need it to be sorted. I suppose I could add everything
to the dictionary, then get an array from that, then sort it.
Thanks for the responses everyone!
-Jan Van Tol
_______________________________________________
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.
Jeff Disher
President and Lead Developer of Spectral Class
Spectral Class: Shedding Light on Innovation
http://www.spectralclass.com/
_______________________________________________
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.