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 protected]> 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 protected], <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 protected]) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
