Re: Abstract Text Example and Question
Re: Abstract Text Example and Question
- Subject: Re: Abstract Text Example and Question
- From: Brad Stone <email@hidden>
- Date: Thu, 10 Feb 2011 10:44:57 -0500
Matt and Graham - I knew there was a better approach. I'll look into the things you suggest.
On Feb 10, 2011, at 10:19 AM, Matt Neuburg wrote:
> On Wed, 9 Feb 2011 22:04:58 -0500, Brad Stone <email@hidden> said:
>> I made this code to remove any duplicate words from a large group of text.
>
>> if ([resultArray indexOfObject:s] == NSNotFound)
>
> There's the problem. Who knows how this is implemented? You could be searching the entire array one entry at a time all the way to the end for every single word (if the text goes, say, "fee fi fo fum fum fum fum fum..."). That's why the usual algorithm for this sort of thing involves a dictionary, not an array; access to a key in a dictionary is guaranteed fast because of hashing. Basically you're making a histogram, which is a well-solved problem. If order matters, use both the dictionary *and* some other storage to keep track of the words in the order in which they actually appear. m.
>
> --
> matt neuburg, phd = email@hidden, <http://www.apeth.net/matt/>
> A fool + a tool + an autorelease pool = cool!
> AppleScript: the Definitive Guide - Second Edition!
> http://www.apeth.net/matt/default.html#applescriptthings
_______________________________________________
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