• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Unique strings array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unique strings array


  • Subject: Re: Unique strings array
  • From: Dave DeLong <email@hidden>
  • Date: Fri, 11 Mar 2011 18:37:33 -0800

Nope; the whole point of a set is that it doesn't allow duplicates. @"the" is equal to @"the", so it will only be included once. The documentation is quite clear about this.

And while your NSDictionary trick will work, I wouldn't recommend it. It's a misuse of what a dictionary is supposed to be used for.

Dave

Sent from my iPhone

On Mar 11, 2011, at 6:33 PM, Stevo Brock <email@hidden> wrote:

> Unless I'm missing something, if you have aWord1 = @"the" and aWord2 = @"the", they will both get added to the array/set.
>
> You can also use an NSMutableDictionary - just
>
> for (NSString* word in wordsArray)
>    [dict setObject:anything forKey:word];
>
> NSArray*    uniqueWords = [dict allKeys];
>
> -Stevo
>
>
> On Mar 11, 2011, at 6:19 PM, Dave DeLong wrote:
>
>> Use an NSMutableSet instead. That should have constant lookup time instead of linear (like an array usually is).
>>
>> Dave
>>
>> Sent from my iPhone
>>
>> On Mar 11, 2011, at 6:11 PM, Leonardo <email@hidden> 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
>
> _______________________________________________
>
> 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

References: 
 >Unique strings array (From: Leonardo <email@hidden>)
 >Re: Unique strings array (From: Dave DeLong <email@hidden>)
 >Re: Unique strings array (From: Stevo Brock <email@hidden>)

  • Prev by Date: Core Data NSPredicate
  • Next by Date: Re: Unique strings array
  • Previous by thread: Re: Unique strings array
  • Next by thread: Re: Unique strings array
  • Index(es):
    • Date
    • Thread