replaceObjectAtIndex problem

First sentence: I don’t have any idea what you are saying here - “as I strike an existing Client” ??

Second sentence: It isn’t clear to me whether you should be doing this with arrays at all. Trying to get a handle on what you’re trying to accomplish with your project is difficult without more concrete examples of your files. It sounded like, from your very first post on this project, that you’re starting with many files with text not arrays. Are you converting them to arrays (or lists) first? Maybe string searching techniques or an NSScanner might be a better approach.

Third sentence: You shouldn’t be doing anything with NSDecimalNumbers in ASOC (that’s an Obj-C thing)

Fourth sentence: “offset of an instance of a particular Client” I don’t know what you mean by this either. It isn’t hard to get the offset of a known string within a larger string, but I don’t know if that’s what you’re trying to do here.

I can try to help you convert some of your code to Objective-C, but in the absence of a good idea of the overall structure of your project, I don’t know if that would be useful. The code you just posted has four things that come from the outside of that code snippet: TempWholeList, separateOutClient(paragraphCycle), theClientList, and theClientListNumberKeeper. I would have to pass these all in to the Obj-C method, and I would have to know what they are to do that. I could offer a lot more useful help if you could provide an example of one of your files (with fake data if need be) and a clear idea of what output you want from the project. You can contact me by email if you want to do this offline.

Ric

Ric, I’ve sent you an off list contact.

The data is in files (365 of them) in yearly folders.

The data is in paragraphs like so

2009-03-18 140747Z,Brian Christmas bec9@tpg.com.au,indesign fixed script

I need to pull out the email address (between the commas), then strip any garbage off the front eg

2009-03-18 140747Z,??? Brian Christmas bec9@tpg.com.au,indesign fixed script

would need the ??? (space) removed.

Also, sometimes the addresses dont have a prefix eg.

2009-03-18 140747Z,bec9@tpg.com.au,indesign fixed script

Then we need to count how many times each Client occurs. And this must be done in between set dates if necessary.

With 48,000 individual entries, over 4600 Clients, everything is slow. The code that you did for me is taking about 200 seconds, but I thought it might be faster if…

  1. As I loop through each paragraph, in each file, I add any new clients to an array. (was originally a list).

  2. I simultaneously add a 1 to a matching array (which also once was a list).

  3. As I find a Client that already exists in the array, I then want to add 1 to the matching number array.

  4. To add that number 1, I have to loop through the Client array until I find a match, then add 1 to the matching number array

  5. Looping through the clients to get a match is slow, but as the loop is the slowest part, i wondered about replacing it with ObjC code.

  6. The above looping adds about 2000 seconds to a 2060 second search, so if I could reduce it to 2000/270 seconds it would be a huge difference

Regards

Santa

Why not? NSMutableArray is an Objective-C thing too. So you should keep those things together if you want to improve speed. Getting an object from an NSMutableArray, convert it to an applescript class, increment the value, convert the value back to an cocoa object and place it in the array seems for me unnecessary. So when using NSDecimalNumber you can void these types of overhead which results in a faster program. If he wants the value later back to applescript he can use doubleValue to get it back to applescript.

G’day DJ

It’s the looping that’s killing this method, everything else works OK.

I just double checked.

Without the looping to find a matching Client… 30 seconds

With the looping … 2438 seconds

Regards

Santa

Hi,

I haven’t had time to read the whole thread but it seems to me that it is repeating through the loop with ASOC that is the issue.

I had this problem and the solution was to code in Objective-C.

Here is the solution to my problem which may point you in another direction.

The link to the post is:
http://macscripter.net/viewtopic.php?id=34983

It may not be what you wanted to here but I think Objective-C is the solution.

All the best

Terry

NSDecimalNumber is not mutable, from the documentation:
NSDecimalNumber, an immutable subclass of NSNumber, provides an object-oriented wrapper for doing base-10 arithmetic.

Sorry you’re right about that stefan. Sorry for the misunderstanding but what I mean is that NSDecimatNumber can sum numbers so you can use:

set x to NSDecimalNumber's numberWithDouble_(100)
set y to NSDecimalNumber's numberWithDouble_(50)
log (x's decimalNumberByAdding_(y))

–x is not changed but x returns a new NSDecimalNumber

@Tellboy. Similar (simple) functions can be achieved in applescript to run in less then a second too. It’s just writing the loops in a wrong way.