Re: Unique strings array
Re: Unique strings array
- Subject: Re: Unique strings array
- From: Roland King <email@hidden>
- Date: Sat, 12 Mar 2011 10:19:45 +0800
well you could try NSSet for a start, see how that works for you. That at least uses a hash for lookup, all you have to do is insert every word and the set will do the rest for you. That whole loop becomes
NSSet *uniqueWords = [ NSSet setWithArray:wordsArray ];
There are many other ways to do this depending on where the words are coming from and what you're going to do with them, but I shall assume at this point that you need to do this and this is one reasonable way to attempt it.
On 12-Mar-2011, at 10:11 AM, Leonardo wrote:
> Hi,
> I have to extract a list of "unique words" from an array of hundred
> thousands words and put them into an uniqueWordsArray. I already succeeded
> but the task is very very slow because I don't index the uniqueWordsArray.
> So my question is: how to index the array and get a fast check?
> Actually I do:
>
> for(NSString *aWord in wordsArray){
> if([uniqueWordsArray containsObject:aWord] == NO){
> [uniqueWordsArray addObject:aWord];
> }
> }
>
> You understand well that the task works fast at the beginning, but it gets
> slower and slower at any word added to the uniqueWordsArray.
> What's the best way to do that?
> Should I use the internal SQLLite database? CoreData? Other?
>
>
> Regards
> -- Leonardo
>
>
> _______________________________________________
>
> 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