Re: How to use an array to solve the following...
On Tue, Feb 21, 2012 at 11:16 PM, Geoff Canyon Rev gcanyon+...@gmail.comwrote: but I've been fooled by the near-infinite speed of repeat for each too many times to count. Haven't we all. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
Sorry got caught up on an issue... So far things look very fast and seem to give the results I need (will confirm as I use larger data sets that have a known answer). But this does bring up a question and doing more than planned with the final lists... If the final list is kept in sequential order based on the xs column I thought that either an sqlite database or arrays could be used for a basic query. I prefer arrays since it is probably easier to use for the desired result. The query would be based on the user selecting a starting xs value and and ending xs value with the resulting rows between (and including the starting and ending value rows). Everything would be based on this query of the final list. For example a user wants an starting xs value of 10 and an ending xs value of 40 I think that if the keys are sequential (the keys being the first column - xs) then it would be a fast solution using arrays since you should be able to determine the starting line and ending line of the array without needing to cycle through every line and then just produce a new array / list. Again, is this a good use for an array? A database would work and be more flexible if the query was going to have multiple requirements but for my case it would be over kill...true? Or will Kay prove it to be faster with just lists :-) xs wtgt 10 632 --starting value 20 0 0 30 0 0 40 0 67 --ending value 50 0 0 70 0 0 80 7 0 90 0 0 1200 0 1302355 produces a new list / array xs wtgt 10 632 20 0 0 30 0 0 40 0 67 On Mon, Feb 20, 2012 at 10:37 PM, Kay C Lan lan.kc.macm...@gmail.comwrote: On Tue, Feb 21, 2012 at 10:20 AM, Geoff Canyon Rev gcanyon+...@gmail.com wrote: For items, lines, and words, using item/line/word of myContainer gets worse the larger the container is. For character and with arrays, it doesn't. Excellent rules of thumb, though there is a caveat to all this. Unfortunately I haven't seen a further response from Glen, as I was going to wait to ask one more question, before offering further suggestions; but I'll now offer it anyway. Glen doesn't mention what the final use/access of the data will be. If you are only every going to deal with the data as a whole, then repeat for each line will generally be the fastest. On the other hand, if after preparing all your lists and merging them, the final purpose is to pick small bits and pieces out of it from here, there and anywhere, arrays (or a db) might be better. So the caveat is, always test and compare. It might be faster to create and merge the data using repeat for each, but slower to access it that way. It might be slower to merge the data using arrays, but faster to access it final format. Here are some comparisons I carried out. I created a variable of 100 lines containing 11 items similar to Glen's data. I created an array of the same data. It took less time to create the array. I then accessed the data 1 times in the following ways. put item 2 of line 1 into tStore2 --because item 1 is an id not data put item 11 of line 100 into tStore2 put item -1 of line 1 into tStore2 put item -1 of line -1 into tStore2 put aStore[1][1] into tStore2 put aStore[100][10] tStore2 For the final 2 repeat for each cases I had to add the overhead of an if statement to test that I was at the right line, and simply put the 1st or last item into tStore2. In both cases I immediately exit repeat so that it did not waste cycles processing lines it didn't have too. Here are the results: Created tStore in 4962ms Created aStore[][] in 30463ms For 1 cycles. Finding the 1st item of the 1st line using direct reference = 3ms Finding the last item of the last line using direct reference = 440294ms Finding the -1 item of the 1st line using direct reference = 5ms Finding the -1 item of the -1 line using direct reference = 733095ms Finding the first child of the first key = 3ms Finding the last child of the last key = 3ms Finding 1st item of 1st line using repeat for each line = 0ms Finding last item of last line using repeat for each line = 454ms The results speak for themselves. Repeat for each can be blindingly fast, but naturally, as Geoff pointed out, slows the further into the data you need to go, and will therefore give an inconsistent feel to a user. Arrays on the other hand might not be the fastest, but they not slow, and will always respond the same way no matter where in the data you look. What ever you do, avoid using item -1 of line -1 One last thing. Normally when I do these speed test I don't 'do' anything else on my computer, although other apps might be loaded in the background. In this case, because it was taking so long I did read some emails, which is probably real life conditions, I mean would wait 12min sitting doing nothing
Re: How to use an array to solve the following...
Depends on how big the list is. Unless there's a faster method than the one I used (or you're using slower hardware than I am), you should be okay up to about 100,000 rows using something like: repeat for each line L in the keys of yourArray if L 20 and L 60 then put L cr after R end repeat -- 20 and 60 are your filter values, -- R is your result set On Tue, Feb 21, 2012 at 2:29 AM, Glen Bojsza gboj...@gmail.com wrote: If the final list is kept in sequential order based on the xs column I thought that either an sqlite database or arrays could be used for a basic query. I prefer arrays since it is probably easier to use for the desired result. The query would be based on the user selecting a starting xs value and and ending xs value with the resulting rows between (and including the starting and ending value rows). ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
On Tue, Feb 21, 2012 at 4:29 PM, Glen Bojsza gboj...@gmail.com wrote: Or will Kay prove it to be faster with just lists :-) Already proven. I agree with Geoff. For the data example you have provided and the queries you are suggesting, LC can easily handle it using repeat for each line and an if statement as shown by Geoff. My own tests seem to indicate that as your individual data is so small, even with a 100 lines it's possible to do 1 searches in under 0.5 sec! ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
I was thinking more along the lines (no pun intended) of - find line number of starting value (for example line 578 ) - find line line number of ending value (for example 12125) put lines 578 to 12125 into results Can this be done verses looping through each line since we know the xs column is sequentially in order? On Tue, Feb 21, 2012 at 1:54 AM, Geoff Canyon Rev gcanyon+...@gmail.comwrote: Depends on how big the list is. Unless there's a faster method than the one I used (or you're using slower hardware than I am), you should be okay up to about 100,000 rows using something like: repeat for each line L in the keys of yourArray if L 20 and L 60 then put L cr after R end repeat -- 20 and 60 are your filter values, -- R is your result set ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
Glen, Look at my test results more closely: Finding the 1st item of the 1st line using direct reference = 3ms Finding the last item of the last line using direct reference = 440294ms Finding the -1 item of the 1st line using direct reference = 5ms Finding the -1 item of the -1 line using direct reference = 733095ms Finding the first child of the first key = 3ms Finding the last child of the last key = 3ms Finding 1st item of 1st line using repeat for each line = 0ms Finding last item of last line using repeat for each line = 454ms Using direct reference is always slower than repeat for each, ESPECIALLY if the data is toward the end. I would amend Geoff's script to this: repeat for each line L in the keys of yourArray if L 20 then put L cr after R if L 60 then exit repeat end if end if end repeat Don't waste cyling through lines you don't have to. HTH On Tue, Feb 21, 2012 at 5:37 PM, Glen Bojsza gboj...@gmail.com wrote: I was thinking more along the lines (no pun intended) of - find line number of starting value (for example line 578 ) - find line line number of ending value (for example 12125) put lines 578 to 12125 into results Can this be done verses looping through each line since we know the xs column is sequentially in order? On Tue, Feb 21, 2012 at 1:54 AM, Geoff Canyon Rev gcanyon+...@gmail.com wrote: Depends on how big the list is. Unless there's a faster method than the one I used (or you're using slower hardware than I am), you should be okay up to about 100,000 rows using something lik repeat for each line L in the keys of yourArray if L 20 and L 60 then put L cr after R end repeat -- 20 and 60 are your filter values, -- R is your result set ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
Then repeat for is King in Livecode! thanks for everyone's feedback . On Tue, Feb 21, 2012 at 2:52 AM, Kay C Lan lan.kc.macm...@gmail.com wrote: Glen, Look at my test results more closely: Finding the 1st item of the 1st line using direct reference = 3ms Finding the last item of the last line using direct reference = 440294ms Finding the -1 item of the 1st line using direct reference = 5ms Finding the -1 item of the -1 line using direct reference = 733095ms Finding the first child of the first key = 3ms Finding the last child of the last key = 3ms Finding 1st item of 1st line using repeat for each line = 0ms Finding last item of last line using repeat for each line = 454ms Using direct reference is always slower than repeat for each, ESPECIALLY if the data is toward the end. I would amend Geoff's script to this: repeat for each line L in the keys of yourArray if L 20 then put L cr after R if L 60 then exit repeat end if end if end repeat Don't waste cyling through lines you don't have to. HTH On Tue, Feb 21, 2012 at 5:37 PM, Glen Bojsza gboj...@gmail.com wrote: I was thinking more along the lines (no pun intended) of - find line number of starting value (for example line 578 ) - find line line number of ending value (for example 12125) put lines 578 to 12125 into results Can this be done verses looping through each line since we know the xs column is sequentially in order? On Tue, Feb 21, 2012 at 1:54 AM, Geoff Canyon Rev gcanyon+...@gmail.com wrote: Depends on how big the list is. Unless there's a faster method than the one I used (or you're using slower hardware than I am), you should be okay up to about 100,000 rows using something lik repeat for each line L in the keys of yourArray if L 20 and L 60 then put L cr after R end repeat -- 20 and 60 are your filter values, -- R is your result set ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
On Tue, Feb 21, 2012 at 4:29 PM, Glen Bojsza gboj...@gmail.com wrote: For example a user wants an starting xs value of 10 and an ending xs value of 40 I think that if the keys are sequential (the keys being the first column - xs) then it would be a fast solution using arrays since you should be able to determine the starting line and ending line of the array without needing to cycle through every line and then just produce a new array / list. Again, is this a good use for an array? Looking at your example more closely it could be possible to achieve some extremely fast results with arrays. But as always, if speed is really important to you you'd need to do some comparitive tests. As I think I've demonstrated it's not too hard to whip up a couple of test script to time solutions. Some determining factors. In a previous post you indicated that there would be 10 ?t columns. When you are doing your search are you after all data from every column? Then setting up flat data and doing repeat for each line will probably be the fastest. Alternatively you could create an array with the xs as the key and the entire line as the data. You indicate that your searches would be of sequential lines. If that is ALWAYS true, then repeat for each line will be very fast, if there is any possibility that the searches will not be of sequential lines, then some overhead will be introduced. Even so repeat for each line will still be fast. Conversely, it would be quite easy to create a list of every xs values from, in your example 10 to 40 and do a repeat for each to extract the data from an array. If there was a possibility that you didn't require the whole line of data, but just an ht or gt value, then this would not carry any overhead with an array search. On average you could get quicker results with an array but they are only small differences, and if your queries are less than 10s of thousands, then the amounts are so small they are probably unnoticeable. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
Once the final list has been made it could have up to 10 ?t columns but the query is only for the lines identified as start and end based on the first column which is xs. There would be no other queries involving the data in the ?t columns the whole line that meets the xs query is moved to a new list. YES xs column will ALWAYS be sequential. The good news is that the lists may grow as high as 1,000,000 lines and are as little as 30,000. The methods you have described are fast enough not to justify going to sqlite (which in itself has a learning curve and adds to the stack overhead). thanks again. On Tue, Feb 21, 2012 at 7:06 AM, Kay C Lan lan.kc.macm...@gmail.com wrote: On Tue, Feb 21, 2012 at 4:29 PM, Glen Bojsza gboj...@gmail.com wrote: For example a user wants an starting xs value of 10 and an ending xs value of 40 I think that if the keys are sequential (the keys being the first column - xs) then it would be a fast solution using arrays since you should be able to determine the starting line and ending line of the array without needing to cycle through every line and then just produce a new array / list. Again, is this a good use for an array? Looking at your example more closely it could be possible to achieve some extremely fast results with arrays. But as always, if speed is really important to you you'd need to do some comparitive tests. As I think I've demonstrated it's not too hard to whip up a couple of test script to time solutions. Some determining factors. In a previous post you indicated that there would be 10 ?t columns. When you are doing your search are you after all data from every column? Then setting up flat data and doing repeat for each line will probably be the fastest. Alternatively you could create an array with the xs as the key and the entire line as the data. You indicate that your searches would be of sequential lines. If that is ALWAYS true, then repeat for each line will be very fast, if there is any possibility that the searches will not be of sequential lines, then some overhead will be introduced. Even so repeat for each line will still be fast. Conversely, it would be quite easy to create a list of every xs values from, in your example 10 to 40 and do a repeat for each to extract the data from an array. If there was a possibility that you didn't require the whole line of data, but just an ht or gt value, then this would not carry any overhead with an array search. On average you could get quicker results with an array but they are only small differences, and if your queries are less than 10s of thousands, then the amounts are so small they are probably unnoticeable. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
On Tue, Feb 21, 2012 at 3:52 AM, Kay C Lan lan.kc.macm...@gmail.com wrote: repeat for each line L in the keys of yourArray if L 20 then put L cr after R if L 60 then exit repeat end if end if end repeat Don't waste cyling through lines you don't have to. Agreed, if the keys are sorted. I was assuming that they were coming straight from the keys of the array (as shown in my example) so you'd have to test the whole thing. I'd be curious which is faster: get the keys sort the keys do your script or get the keys do my script My first instinct is to say your solution, for the obvious reasons, but I've been fooled by the near-infinite speed of repeat for each too many times to count. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
On Tue, Feb 21, 2012 at 8:36 AM, Glen Bojsza gboj...@gmail.com wrote: The good news is that the lists may grow as high as 1,000,000 lines and are as little as 30,000. 1,000,000 lines is pretty big. If you're guaranteed to be working on a recent machine, then perhaps it would be okay. But that's certainly pushing the limits of what makes sense in a repeat for each. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
Pete wrote: Interesting, and it kinda makes sense. For elements, there's no positioning required like with lines/words/item, just a case of cycling through the keys - which is what repeat for each line x in the keys of array does I suppose. As with most things in computing, the truly optimal solution comes with a lot of depends; total date size, size of elements, distance from the start of a chunk to the value being obtained in it, how deeply nested are the array keys - all those and more play a role in total performance, which can sometimes yield unexpected results. One challenge with arrays is their use in CGIs, where total throughput performance is unusually critical since the app is born, lives, and dies all in the space of satisfying a single request from the user. The problem with arrays in that context is that they don't exist with the routine begins, since the engine itself needs to be loaded. Arrays offer blinding speed for random access, but they're able to do this because they rely on memory-specific structures, leaving us with the question: how do we load the array from a cold start? One can use custom properties, or arrayEncode/arrayDecode, or split/combine, but all of them are only slightly optimized versions of what you'd need to do if you had to script it yourself using repeat for each line... and stuffing the array elements sequentially. So oddly enough, if the context of use requires that you take into account the loading of the array, total throughput will often be substantially slower than scooping up a delimited file and using chunk expressions on it. Even outside of a total-throughput context, I've seen other cases where arrays can be slower than repeat for each, such as deeply-nested arrays (say, four levels deep). In such cases, while each traversal of the hash used to identify the location of the element value is pretty darn fast, you'll have to do four traversals of each hash to get at each element, and that can add up. Moreover, arrays can impact memory in ways that chunks don't, because in a world where we don't yet have structs (see http://quality.runrev.com/show_bug.cgi?id=8304), element labels are replicated for every key. With a tab-delimited list the non-data overhead is one char per field, but with arrays it's the length of the key for every field, which can double the size of the data in memory if the keys are as long as the data. So alas, as you folks have done here, many times the only way to know for sure what an optimal solution will be is to test it. If you find yourself doing this sort of thing often, I've put together a few tips on benchmarking performance in this LiveCode Journal article: http://livecodejournal.com/tutorials/benchmarking-revtalk.html -- Richard Gaskin Fourth World LiveCode training and consulting: http://www.fourthworld.com Webzine for LiveCode developers: http://www.LiveCodeJournal.com LiveCode Journal blog: http://LiveCodejournal.com/blog.irv ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
Even with repeat for each line, the chunk has to be parsed in memory for returns before proceeding. An array is by nature already parsed. As has been discussed before, the repeat for each command is so fast because it parses the memory used by the chunk, creating a list of pointers (forgive me if that is the wrong word) to the delimiters. It only has to do this once, as opposed to each time through the loop which is what makes it so fast. An array is already parsed, although the engine may reparse it for the purposes of the command, I do not know. Repeat for each line x in the keys of array y would seem at a glance to have to reevaluate the keys of array each time through the loop, wouldn't it? You must mean you get the keys first in a variable and then use that. Bob On Feb 20, 2012, at 6:54 PM, Pete wrote: Interesting, and it kinda makes sense. For elements, there's no positioning required like with lines/words/item, just a case of cycling through the keys - which is what repeat for each line x in the keys of array does I suppose. Pete On Mon, Feb 20, 2012 at 6:20 PM, Geoff Canyon Rev gcanyon+...@gmail.comwrote: Certainly correct, but there is not the tremendous performance advantage to using for each element in... For items, lines, and words, using item/line/word of myContainer gets worse the larger the container is. For character and with arrays, it doesn't. In my quick testing here, there's just about no performance advantage to doing repeat for each element. There's about a 4x benefit for using repeat for each char over repeat with i = 1 to length(myString) But note that it seems to be 4x regardless of the string length. That isn't the case with items, lines, and words -- there, the longer your container, the more you'll suffer. On Mon, Feb 20, 2012 at 3:02 PM, Bob Sneidar b...@twft.com wrote: Also each element in array Bob On Feb 20, 2012, at 10:34 AM, gcanyon+rev wrote: any time you find yourself writing: repeat with i = 1 to the number of lines|words|items of someContainer stop. Rewrite it as: repeat for each line|word|item in someContainer ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode -- Pete Molly's Revenge http://www.mollysrevenge.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
Take for example retrieving a large data set from an SQL db. You can retrieve it as a cursor, and array or a string. Cursors are read only and I don't see the advantage of working with them. That leaves only arrays and strings. So if you *can* get the data as an array, and sorting is not an issue, I'd say use an array. If the data you are working with can only be gotten as a string, such as a web query, then you gain nothing parsing it into an array first. Bob On Feb 21, 2012, at 8:48 AM, Richard Gaskin wrote: Pete wrote: Interesting, and it kinda makes sense. For elements, there's no positioning required like with lines/words/item, just a case of cycling through the keys - which is what repeat for each line x in the keys of array does I suppose. As with most things in computing, the truly optimal solution comes with a lot of depends; total date size, size of elements, distance from the start of a chunk to the value being obtained in it, how deeply nested are the array keys - all those and more play a role in total performance, which can sometimes yield unexpected results. One challenge with arrays is their use in CGIs, where total throughput performance is unusually critical since the app is born, lives, and dies all in the space of satisfying a single request from the user. The problem with arrays in that context is that they don't exist with the routine begins, since the engine itself needs to be loaded. Arrays offer blinding speed for random access, but they're able to do this because they rely on memory-specific structures, leaving us with the question: how do we load the array from a cold start? ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
Bob Sneidar wrote: Repeat for each line x in the keys of array y would seem at a glance to have to reevaluate the keys of array each time through the loop, wouldn't it? You must mean you get the keys first in a variable and then use that. If I understand how the engine treats that, it seems that it gets the keys only once up front, since anything used with repeat for each is considered unchangeable during the repeat. -- Richard Gaskin Fourth World LiveCode training and consulting: http://www.fourthworld.com Webzine for LiveCode developers: http://www.LiveCodeJournal.com LiveCode Journal blog: http://LiveCodejournal.com/blog.irv ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
You are probably right, I imagined in my mind that when the engine parses the chunk, it had to already be in memory, as in a variable or array. Since the thing being parsed was a statement that evaluated to something, it seemed that the engine would have nothing in existence to parse to begin with, and would have to create it. I suppose then that upon evaluating the repeat for each statement the first time, it would create a temporary place in memory inaccessible to the code, which would cease to exist once the repeat loop was done. I can see other functions and commands would have to do something similar, evaluating a statement, as in put line (the number of lines of myvar) of myVar , but the value of the number of lines of myVar must cease to exist once the statement was evaluated. In the repeat for each loop, the value would have to be retained while the repeat loop ran, and then purged when it was done. It's odd to think like that, but the repeat for each command *might* be written this way. I suppose it would have to be. Bob On Feb 21, 2012, at 12:34 PM, Richard Gaskin wrote: Bob Sneidar wrote: Repeat for each line x in the keys of array y would seem at a glance to have to reevaluate the keys of array each time through the loop, wouldn't it? You must mean you get the keys first in a variable and then use that. If I understand how the engine treats that, it seems that it gets the keys only once up front, since anything used with repeat for each is considered unchangeable during the repeat. -- Richard Gaskin Fourth World LiveCode training and consulting: http://www.fourthworld.com Webzine for LiveCode developers: http://www.LiveCodeJournal.com LiveCode Journal blog: http://LiveCodejournal.com/blog.irv ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
As Richard said, the engine is smart enough to avoid this pitfall. So no, it's perfectly fine to say repeat for each line x in the keys of array y even if the list of keys is large. On Tue, Feb 21, 2012 at 12:03 PM, Bob Sneidar b...@twft.com wrote: Repeat for each line x in the keys of array y would seem at a glance to have to reevaluate the keys of array each time through the loop, wouldn't it? You must mean you get the keys first in a variable and then use that. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
On Feb 19, 2012, at 10:42 PM, dunb...@aol.com wrote: Kay's is much faster than mine. Don't worry about it, it happens to just about every person who's had experience with HyperCard when they come over to LiveCode: the repeat for each aha! moment: any time you find yourself writing: repeat with i = 1 to the number of lines|words|items of someContainer stop. Rewrite it as: repeat for each line|word|item in someContainer With the other way, every time in the repeat that you use chunk i of someContainer you're forcing the engine to count through all the chunks up to that one. With repeat for each you're not. If you need to know which chunk you're on, use an index variable. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
Also each element in array Bob On Feb 20, 2012, at 10:34 AM, gcanyon+rev wrote: any time you find yourself writing: repeat with i = 1 to the number of lines|words|items of someContainer stop. Rewrite it as: repeat for each line|word|item in someContainer ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
Bob, Can you give a quick example of this? I have always used for each line in the keys of array. Thanks Mike Sent from my BlackBerry device on the Rogers Wireless Network -Original Message- From: Bob Sneidar b...@twft.com Sender: use-livecode-boun...@lists.runrev.com Date: Mon, 20 Feb 2012 13:02:12 To: How to use LiveCodeuse-livecode@lists.runrev.com Reply-To: How to use LiveCode use-livecode@lists.runrev.com Subject: Re: How to use an array to solve the following... Also each element in array Bob On Feb 20, 2012, at 10:34 AM, gcanyon+rev wrote: any time you find yourself writing: repeat with i = 1 to the number of lines|words|items of someContainer stop. Rewrite it as: repeat for each line|word|item in someContainer ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
ON mouseUp pMouseBtnNo put the dgData of group dgTableData into theDataA REPEAT FOR each element theRecordA in theDataA add 1 to theItemNum put theRecordA[reservationid] into item theItemNum of theReservationList END REPEAT put theReservationList END mouseUp I have a datagrid of meeting reservations. There are 25 rows. It contains a column called reservationid. Given that, when done the message contains this: 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25 Note that datagrid data is a numbered array, each element of which is another array, each element of which corresponds to a column in the datagrid. Note also that were I to try to alter the contents of theDataA inside the repeat loop the results would be unreliable for the reasons mentioned before. Using your method of getting the keys first and then using repeat for each line in theKeyList has the advantage that you can alter the contents of the array itself without a problem. Bob On Feb 20, 2012, at 1:06 PM, miked...@gmail.com wrote: Bob, Can you give a quick example of this? I have always used for each line in the keys of array. Thanks Mike Sent from my BlackBerry device on the Rogers Wireless Network ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
I tend to use for each line in the keys also, mainly because element returns the contents of the array and I often find myself needing to know the key value. Plus if you need to get the array elements in key sequence, I think you have put the keys into a variable and sort them then base the repeat loop on the lines in the sorted variable... I think??? Pete On Mon, Feb 20, 2012 at 1:06 PM, miked...@gmail.com wrote: Bob, Can you give a quick example of this? I have always used for each line in the keys of array. Thanks Mike Sent from my BlackBerry device on the Rogers Wireless Network -Original Message- From: Bob Sneidar b...@twft.com Sender: use-livecode-boun...@lists.runrev.com Date: Mon, 20 Feb 2012 13:02:12 To: How to use LiveCodeuse-livecode@lists.runrev.com Reply-To: How to use LiveCode use-livecode@lists.runrev.com Subject: Re: How to use an array to solve the following... Also each element in array Bob On Feb 20, 2012, at 10:34 AM, gcanyon+rev wrote: any time you find yourself writing: repeat with i = 1 to the number of lines|words|items of someContainer stop. Rewrite it as: repeat for each line|word|item in someContainer ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode -- Pete Molly's Revenge http://www.mollysrevenge.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
Pete, you are correct. Lines of the keys are not sorted. Bob, thanks. I have not ever seen element used before. Interesting. -= Mike Sent from my BlackBerry device on the Rogers Wireless Network -Original Message- From: Pete p...@mollysrevenge.com Sender: use-livecode-boun...@lists.runrev.com Date: Mon, 20 Feb 2012 13:59:48 To: How to use LiveCodeuse-livecode@lists.runrev.com Reply-To: How to use LiveCode use-livecode@lists.runrev.com Subject: Re: How to use an array to solve the following... I tend to use for each line in the keys also, mainly because element returns the contents of the array and I often find myself needing to know the key value. Plus if you need to get the array elements in key sequence, I think you have put the keys into a variable and sort them then base the repeat loop on the lines in the sorted variable... I think??? Pete On Mon, Feb 20, 2012 at 1:06 PM, miked...@gmail.com wrote: Bob, Can you give a quick example of this? I have always used for each line in the keys of array. Thanks Mike Sent from my BlackBerry device on the Rogers Wireless Network -Original Message- From: Bob Sneidar b...@twft.com Sender: use-livecode-boun...@lists.runrev.com Date: Mon, 20 Feb 2012 13:02:12 To: How to use LiveCodeuse-livecode@lists.runrev.com Reply-To: How to use LiveCode use-livecode@lists.runrev.com Subject: Re: How to use an array to solve the following... Also each element in array Bob On Feb 20, 2012, at 10:34 AM, gcanyon+rev wrote: any time you find yourself writing: repeat with i = 1 to the number of lines|words|items of someContainer stop. Rewrite it as: repeat for each line|word|item in someContainer ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode -- Pete Molly's Revenge http://www.mollysrevenge.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
Certainly correct, but there is not the tremendous performance advantage to using for each element in... For items, lines, and words, using item/line/word of myContainer gets worse the larger the container is. For character and with arrays, it doesn't. In my quick testing here, there's just about no performance advantage to doing repeat for each element. There's about a 4x benefit for using repeat for each char over repeat with i = 1 to length(myString) But note that it seems to be 4x regardless of the string length. That isn't the case with items, lines, and words -- there, the longer your container, the more you'll suffer. On Mon, Feb 20, 2012 at 3:02 PM, Bob Sneidar b...@twft.com wrote: Also each element in array Bob On Feb 20, 2012, at 10:34 AM, gcanyon+rev wrote: any time you find yourself writing: repeat with i = 1 to the number of lines|words|items of someContainer stop. Rewrite it as: repeat for each line|word|item in someContainer ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
Interesting, and it kinda makes sense. For elements, there's no positioning required like with lines/words/item, just a case of cycling through the keys - which is what repeat for each line x in the keys of array does I suppose. Pete On Mon, Feb 20, 2012 at 6:20 PM, Geoff Canyon Rev gcanyon+...@gmail.comwrote: Certainly correct, but there is not the tremendous performance advantage to using for each element in... For items, lines, and words, using item/line/word of myContainer gets worse the larger the container is. For character and with arrays, it doesn't. In my quick testing here, there's just about no performance advantage to doing repeat for each element. There's about a 4x benefit for using repeat for each char over repeat with i = 1 to length(myString) But note that it seems to be 4x regardless of the string length. That isn't the case with items, lines, and words -- there, the longer your container, the more you'll suffer. On Mon, Feb 20, 2012 at 3:02 PM, Bob Sneidar b...@twft.com wrote: Also each element in array Bob On Feb 20, 2012, at 10:34 AM, gcanyon+rev wrote: any time you find yourself writing: repeat with i = 1 to the number of lines|words|items of someContainer stop. Rewrite it as: repeat for each line|word|item in someContainer ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode -- Pete Molly's Revenge http://www.mollysrevenge.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
On Feb 20, 2012, at 9:37 PM, Kay C Lan wrote: Anyone want to test the speed of finding data in a 100 line variable using char -1 of word -1 of item -1 of line -1? Hi, Kay. Sure. How do I get the script? I'd guess that almost all the time goes into the line -1, and within that line there are so few items and words and chars that the engine will eat them in an instant, at least relatively speaking. Will your script compare what you suggested above to the speed just for line -1? -- Dick ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
You can get away with straight text for small data sets, but I would never suggest using a single variable and line references for random access on anything more than a few tens of thousands of lines -- although I will point out that in your test, even working with a million lines meant a worst case scenario of 1/10th of a second. But that isn't what repeat for each is about. It's for doing something with all the data, either sequentially or in aggregate. If you need random access to a large data set, then an array or a database is clearly the way to go. On Mon, Feb 20, 2012 at 11:37 PM, Kay C Lan lan.kc.macm...@gmail.comwrote: Excellent rules of thumb, though there is a caveat to all this. Unfortunately I haven't seen a further response from Glen, as I was going to wait to ask one more question, before offering further suggestions; but I'll now offer it anyway. Glen doesn't mention what the final use/access of the data will be. If you are only every going to deal with the data as a whole, then repeat for each line will generally be the fastest. On the other hand, if after preparing all your lists and merging them, the final purpose is to pick small bits and pieces out of it from here, there and anywhere, arrays (or a db) might be better. So the caveat is, always test and compare. It might be faster to create and merge the data using repeat for each, but slower to access it that way. It might be slower to merge the data using arrays, but faster to access it final format. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
Glen. I sort of get what you are trying to do, and yes, arrays will be the most compact way to do it, though regular variables can work as well. But what happens if you already have the xs values in conecutive by 10 order? Are you allowed to bump later values by 10? In other words, are you required to insert values at certain places in the list? Does this matter? I don't see the rationale behind where you inserted new values in your example. Or in yet other words, why can't new data be appended to the list, incremented by 10 in the xs portion? This is something I need to know to even start thinking about a method. Craig Newman -Original Message- From: Glen Bojsza gboj...@gmail.com To: How to use LiveCode use-livecode@lists.runrev.com Sent: Sun, Feb 19, 2012 1:56 pm Subject: How to use an array to solve the following... Having limited experience with arrays I thought this might be a good question to ask the group. Is the use of arrays to solve this appropriate? Efficient? Fast? If the answers are yes then it will help with the bigger problem that I am trying to address but for now I am looking for advice or help on how to do this using arrays... just a note the size that the solution would need to work on would involve a couple of hundred thousand rows. I have the following text field example with data Pacer xswt 104 207 40 22 60 71 12099 20012 I need to be able to ensure that between wt values that there is no more than 10 between xs values (this includes before and after a wt value). If there is then a new xs value must be added with a wt value of 0 This is what the solution should look like (ignoring the -- added comments). Pacer xswt 104 207 300 ---added because of wt =7 at 20 so a xs 0 value is added after 40 22 500 ---added because of wt =22 at 40 so a xs 0 value is added after ***but this then solves the problem of wt 71 at 60??!! 60 71 700 ---added because of wt =71 at 60 so a xs 0 value is added after 110 0 ---added because of wt =99 at 120 so a xs 0 value is added before 12099 130 0 ---added because of wt =99 at 120 so a xs 0 value is added after 190 0 ---added because of wt =12 at 200 so a xs 0 value is added before 20012 I look forward to comments and suggestions. regards, Glen ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
The xs values should only be bumped if the preceding xs value is not the one in sequence using 10 as the increment. No xs value (other than the very first one or the very last one cannot have a neighboring xs value within the increment range. for example xs wt 10 6 80 7 13023 staring with the first xs value we see that the nearest neighbor is more than one 10 increment away so a neighbor must be added and the wt value will always be 0 when adding a neighbor. xs wt 10 6 20 0 this is added 80 7 13023 now we look at the original sequence at the next xs value (we do not start over at the first xs value) so the next xs value is 80 which will need a neighbor to be added on both sides since the closest xs value on either side the lower one is 20 (yes in comparing the nearest neighbor you need to consider new ones added) and upper one is 130. xs wt 10 6 20 0 this is added 70 0 this is added 80 7 90 0 this is added 13023 and now we look at the next xs value from the original sequence which is 130 and since it is the last value it only needs a lower neighbor to be added since 90 is the closest one xs wt 10 6 20 0 this is added 70 0 this is added 80 7 90 0 this is added 1200 this is added 13023 This is now solved! Hopefully this makes the earlier example easier to follow. I am trying to avoid repeat with loops since this may make large data sets very slow verses repeat for statements. Again, maybe with arrays this can be done via keys? The bigger picture will be trying to do this where there may be 3 or more columns. On Sun, Feb 19, 2012 at 4:20 PM, dunb...@aol.com wrote: Glen. I sort of get what you are trying to do, and yes, arrays will be the most compact way to do it, though regular variables can work as well. But what happens if you already have the xs values in conecutive by 10 order? Are you allowed to bump later values by 10? In other words, are you required to insert values at certain places in the list? Does this matter? I don't see the rationale behind where you inserted new values in your example. Or in yet other words, why can't new data be appended to the list, incremented by 10 in the xs portion? This is something I need to know to even start thinking about a method. Craig Newman -Original Message- From: Glen Bojsza gboj...@gmail.com To: How to use LiveCode use-livecode@lists.runrev.com Sent: Sun, Feb 19, 2012 1:56 pm Subject: How to use an array to solve the following... Having limited experience with arrays I thought this might be a good question to ask the group. Is the use of arrays to solve this appropriate? Efficient? Fast? If the answers are yes then it will help with the bigger problem that I am trying to address but for now I am looking for advice or help on how to do this using arrays... just a note the size that the solution would need to work on would involve a couple of hundred thousand rows. I have the following text field example with data Pacer xswt 104 207 40 22 60 71 12099 20012 I need to be able to ensure that between wt values that there is no more than 10 between xs values (this includes before and after a wt value). If there is then a new xs value must be added with a wt value of 0 This is what the solution should look like (ignoring the -- added comments). Pacer xswt 104 207 300 ---added because of wt =7 at 20 so a xs 0 value is added after 40 22 500 ---added because of wt =22 at 40 so a xs 0 value is added after ***but this then solves the problem of wt 71 at 60??!! 60 71 700 ---added because of wt =71 at 60 so a xs 0 value is added after 110 0 ---added because of wt =99 at 120 so a xs 0 value is added before 12099 130 0 ---added because of wt =99 at 120 so a xs 0 value is added after 190 0 ---added because of wt =12 at 200 so a xs 0 value is added before 20012 I look forward to comments and suggestions. regards, Glen ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
On Mon, Feb 20, 2012 at 2:53 AM, Glen Bojsza gboj...@gmail.com wrote: Is the use of arrays to solve this appropriate? Efficient? Fast? From another recent thread, using arrays is slower than repeat for each line, and if the values you give are realistic (not lines with 1 chars) then even if you have a million lines, repeat for each will be fast and efficient. My script below I creat a list of: 10 6 80 7 130 23 140 2 150 22 and the script produces: 106 200 700 807 900 1200 13023 1402 1500 16022 Throw this into a button and see if it works for you: on mouseUp --create a list to start with put 10 tab 6 cr \ 80 tab 7 cr \ 130 tab 23 cr \ 140 tab 2 cr \ 160 tab 22 into tStore --actual work done here set the itemDelimiter to tab put first into tLastItem repeat for each line tLine in tStore put item 1 of tLine into tCheck switch case (tLastItem = first) --don't do anything break case (tCheck - tLastItem 20) put tLastItem + 10 tab 0 cr after tStore2 put tCheck - 10 tab 0 cr after tStore2 break case (tCheck - tLastItem 10) put tCheck - 10 tab 0 cr after tStore2 break end switch put tLine cr after tStore2 put tCheck into tLastItem end repeat put tStore2 into msg end mouseUp HTH ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
Whoops typo, the start dummy list is 10 6 80 7 130 23 140 2 160 22 --- 160, not 150 ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
Here's the same solution, but with 101 records. On my machine, over 3 runs I get, 4924 millisec, 4932 ms, 4914 ms. I'm sure others will now improve on that. There are a couple of extra lines to do the timing which you'd remove for your solution. on mouseUp --create the dummy list put 100 into tRepeat put 10 tab 5 cr after tStore put 10 into tLast repeat tRepeat times put (10 * random(5) + tLast) into tLast put tLast tab random(30) cr after tStore end repeat --do the work here set the itemDelimiter to tab put the millisec into tStartTime put first into tLastItem repeat for each line tLine in tStore put item 1 of tLine into tCheck switch case (tLastItem = first) --don't do anything break case (tCheck - tLastItem 20) put tLastItem + 10 tab 0 cr after tStore2 put tCheck - 10 tab 0 cr after tStore2 break case (tCheck - tLastItem 10) put tCheck - 10 tab 0 cr after tStore2 break end switch put tLine cr after tStore2 put tCheck into tLastItem end repeat put the millisec into tEndTime put (tEndTime - tStartTime) ms into msg end mouseUp ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
Hi Kay, This looks very good mainly the use of case with the decision being the switch... never thought about that. Also, I didn't realize that arrays would be slower... I will test this with some of the data sets ... currently up to 80,000 lines but with values I have indicated... but I like the simplicity. I posted the bigger picture but it got jammed due to size so I just pasted the new info here... The biggest picture would be having 10 lists with each list having the xs column but a different ?t column (wt, gt, st, mt, qt, ... etc) The first and last xs value for each list will always be the same and can start at 10 and go to 100,000+ but other than that there will be randomness in the step increments. The goal would be the same but towards building a master list where each associated column would meet the neighbor criteria with the xs column. You can see the xs column increments grow and the already established column values (in this case wt) get a value of 0 for the new xs increments. Given this and the possible number of columns and values is there still a good approach in using arrays? For example... we see from Pacer List xs wt 10 6 80 7 13023 we got Master list xs wt 10 6 20 0 this is added 70 0 this is added 80 7 90 0 this is added 1200 this is added 13023 Train List xs gt 10 32 40 67 130 55 new master list would be xs wtgt 10 632 20 0 0 30 0 0 -- added to xs updated wt value 40 0 67 -- added to xs updated wt value 50 0 0 -- added to xs updated wt value 70 0 0 80 7 0 90 0 0 1200 0 1302355 ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
I am an old HyperCarder, so I tend to attack things in an old fashioned way. I use arrays, but think that the decisions needed here may not use them to any great advantage. I am usually wrong. I tried this with a worst case list of 20,000 lines, that is, no adjacent lines in your sense, to maximize the length of the derived list. It works fine, but took three minutes to run. The resulting list was 60,000 lines long. Given a field yourField with lots of data in it, a field for the results, and a button, place this in the button script: on mouseup put fld 1 into temp repeat for each line tLine in temp put item 1 of tLine - 10 , 0 return before tLine put return item 1 of line 2 of tLine + 10 , 0 return after tLine put tLine after accum end repeat sort accum numeric by item 1 of each delete line 1 of accum delete the last line of accum repeat with y = the number of lines of accum down to 1 switch case item 1 of line y of accum = item 1 of line (y-1) of accum and item 2 of line y of accum = 0 delete line y of accum break case item 1 of line y of accum = item 1 of line (y-1) of accum and item 2 of line y-1 of accum = 0 delete line y-1 of accum break end switch end repeat put accum into fld 2 end mouseup Someone will find a better algorithm. Craig Newman ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
Kay's is much faster than mine. Well done. Craig Newman -Original Message- From: Glen Bojsza gboj...@gmail.com To: How to use LiveCode use-livecode@lists.runrev.com Sent: Sun, Feb 19, 2012 9:49 pm Subject: Re: How to use an array to solve the following... Hi Kay, This looks very good mainly the use of case with the decision being the switch... never thought about that. Also, I didn't realize that arrays would be slower... I will test this with some of the data sets ... currently up to 80,000 lines but with values I have indicated... but I like the simplicity. I posted the bigger picture but it got jammed due to size so I just pasted the new info here... The biggest picture would be having 10 lists with each list having the xs column but a different ?t column (wt, gt, st, mt, qt, ... etc) The first and last xs value for each list will always be the same and can start at 10 and go to 100,000+ but other than that there will be randomness in the step increments. The goal would be the same but towards building a master list where each associated column would meet the neighbor criteria with the xs column. You can see the xs column increments grow and the already established column values (in this case wt) get a value of 0 for the new xs increments. Given this and the possible number of columns and values is there still a good approach in using arrays? For example... we see from Pacer List xs wt 10 6 80 7 13023 we got Master list xs wt 10 6 20 0 this is added 70 0 this is added 80 7 90 0 this is added 1200 this is added 13023 Train List xs gt 10 32 40 67 130 55 new master list would be xs wtgt 10 632 20 0 0 30 0 0 -- added to xs updated wt value 40 0 67 -- added to xs updated wt value 50 0 0 -- added to xs updated wt value 70 0 0 80 7 0 90 0 0 1200 0 1302355 ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
On Mon, Feb 20, 2012 at 10:47 AM, Glen Bojsza gboj...@gmail.com wrote: The biggest picture would be having 10 lists with each list having the xs column but a different ?t column (wt, gt, st, mt, qt, ... etc) If you are going to many more columns, then an array might be faster, and if speed is the ultimate goal, then you would have to benchmark it to compare, just to be sure. For the repeat for each line approach, you basically have to process each list, create the master list by combining and sorting, then do one final run through the master list whilst confirming there are no repeat values (left column number). Fortunately, because you are using 0, it would be simply a matter of adding all the items of each repeated line together to form a single line with all the correct values. With arrays, time could be saved by not dealing with all the 0 values. ie if you only create array elements for those that exist. If you later test for an element, and it doesn't exist, the result is empty, which is equivalent to 0. The following is not verified so you would have to check the results for accuracy. I've left a breakpoint at the end so you can inspect both tStore which contains all the dummy data, and the final array aData. This should give you a rough idea of how to proceed. I used 76923 repeats of 13 lists so I got a total of 99 cycles so I could roughly compare to the other script. I got 5246ms but it must be appreciated, this is doing a lot more than the previous script, even so, it's pretty quick for a million cycles. HTH on mouseUp --create some dummy data put at,bt,ct,dt,et,ft,gt,ht,it,jt,kt,lt,mt into tHeader put 76923 into tRepeat repeat for each item tItem in tHeader put tItem cr 10 tab 5 cr after tStore put 10 into tLast repeat tRepeat times put (10 * random(4) + tLast) into tLast put tLast tab random(30) cr after tStore end repeat end repeat --work done here set the itemDelimiter to tab put the millisec into tStartTime repeat for each line tLine in tStore put item 1 of tLine into tCheck switch case (tCheck is not an integer) put tCheck into tElement --because of the way I created the list put 0 into tLastItem break case (tCheck - tLastItem 20) put 0 into aData[(tLastItem + 10)][tElement] put 0 into aData[(tCheck - 10)][tElement] put item 2 of tLine into aData[tCheck][tElement] put tCheck into tLastItem break case (tCheck - tLastItem 10) put 0 into aData[(tCheck - 10)][tElement] put item 2 of tLine into aData[tCheck][tElement] put tCheck into tLastItem break case (tCheck - tLastItem = 10) put item 2 of tLine into aData[tCheck][tElement] put tCheck into tLastItem break end switch end repeat put the millisec into tEndTime put (tEndTime - tStartTime) msfor (13 * tRepeat) \ cycles. cr into msg put tStore: cr after msg put tStore after msg put cr cr after msg breakpoint end mouseUp ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: How to use an array to solve the following...
On Feb 19, 2012, at 8:47 PM, Kay C Lan lan.kc.macm...@gmail.com wrote: I'm sure others will now improve on that. I doubt it. You're using repeat for each in a sensible way, and there's rarely something faster than that. If you really wanted to tighten up the repeat, you could do something like this, but I doubt that it would be much faster: put item 1 of tStore into tLastItem repeat for each line tLine in tStore put item 1 of tLine into tCheck put tCheck - tLastItem into x switch case (x 20) put tLastItem + 10 tab 0 cr after tStore2 case (x 10) put tCheck - 10 tab 0 cr after tStore2 end switch put tLine cr after tStore2 put tCheck into tLastItem end repeat ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode