Reverse a list
Mike Bonner
bonnmike at gmail.com
Tue Feb 17 15:29:58 EST 2015
The second is slow, because the current position is not tracked. So, for
line 1, its easy. You grab line 1. For line 2, you count the lines, until
you get to line 2. Same for line 3. Or think of it this way.. If you have
100 lines, and you are grabbing all of them using the second method, The
first line iterates once. The second, 2 times, the 3rd, 3 times, so if you
follow that to conclusion you have 1 + 2 + 3 + 4 + 5.. as each "seek" from
the beginning takes longer. So to iterate through the list of 100 using
that method, you are seeking 5050 times.. For a list of 100.
The other way, just dumps them out in sequence, so the list is hit 100
times, and thats it. I suspect its like the "by position" method, as others
have pointed out. A pointer is kept, so that each new read starts at the
preceding position, though I seem to remember talking to someone who said
there might be changes in the pipe that would allow you to modify things
inline. But I don't remember who I talked to about it! (by inline I mean
"for each line tLine..." letting you modify tLine in place.) This would be
possible if the engine converts it to an indexed array at the start, then
back again at the end. Again, I don't remember who it was that I spoke to,
but it would be an interesting change, if the speed could be kept
comparable.
On Tue, Feb 17, 2015 at 1:11 PM, Mike Kerner <MikeKerner at roadrunner.com>
wrote:
> Peter (Brett),
>
> Help me with the chunking piece, then.
>
> The following is very fast:
> put "INSERT INTO sortTest VALUES :1" into tSQL
> repeat for each line tLine in tDataSet
> revExecuteSQL dbid, tsql, tline
> end repeat
>
> The following is very slow:
> put "INSERT INTO sortTest VALUES :1" into tSQL
> put the number of lines in tDataSet into numLines
> repeat with i = 1 to numLines
> revExecuteSQL dbid, tsql, line i of tDataSet
> end repeat
>
>
> So is randomly retrieving the chunk what makes this slow? In the first
> instance, how is that avoided - is it indexed? If so, what is the overhead
> of creating the index? O(2n)?
>
> On Mon, Feb 16, 2015 at 7:19 PM, Alex Tweedly <alex at tweedly.net> wrote:
>
> > You were right first time ....
> >
> > if you use a reference, then there is no copy created when you do the
> > call; and then you build up the output list.
> >
> > without the reference, there is an initial copy and then you additionally
> > build the output list.
> >
> > So using a reference parameter saves the memory for one copy (plus the
> cpu
> > to create the copy).
> >
> > -- Alex.
> >
> >
> >
> > On 16/02/2015 23:06, Peter M. Brigham wrote:
> >
> >> I wrote:
> >>
> >> I referenced the list and turned the function into a command, saves
> >>> memory (possibly speed?) on very large lists.
> >>>
> >> I just realized that no memory is saved this way because we are building
> >> a new duplicate (reversed) list within the command. So referencing the
> list
> >> has no advantage.
> >>
> >> -- Peter
> >>
> >> Peter M. Brigham
> >> pmbrig at gmail.com
> >> http://home.comcast.net/~pmbrig
> >>
> >>
> >> _______________________________________________
> >> use-livecode mailing list
> >> use-livecode at 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 at lists.runrev.com
> > Please visit this url to subscribe, unsubscribe and manage your
> > subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
> >
>
>
>
> --
> On the first day, God created the heavens and the Earth
> On the second day, God created the oceans.
> On the third day, God put the animals on hold for a few hours,
> and did a little diving.
> And God said, "This is good."
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
More information about the use-livecode
mailing list