Re: Unique strings array
Re: Unique strings array
- Subject: Re: Unique strings array
- From: Conrad Shultz <email@hidden>
- Date: Fri, 11 Mar 2011 18:20:05 -0800
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 3/11/11 6:11 PM, 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];
> }
> }
Have you considered NSSet? I think that
+ (id)setWithArray:(NSArray *)array
should do what you want in one line. It presumably is highly optimized
internally.
(Of course, if you need your results indexed as in an array, you will
need to then transform the set into an array and sort as needed.)
- --
Conrad Shultz
Synthetiq Solutions
www.synthetiqsolutions.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iD8DBQFNethVaOlrz5+0JdURAhvPAJoDSWmRCgLkJUJH/P8voY1VILkJnACdHtj+
wdlNv8gO4leN+ZTU9s6CvjI=
=BiGJ
-----END PGP SIGNATURE-----
_______________________________________________
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