Re: Referencing Nested Sequences
- Posted by Derek Parnell <ddparnell at bigpond.com> Jun 08, 2003
- 482 views
----- Original Message ----- From: <pblonner at optushome.com.au> To: "EUforum" <EUforum at topica.com> Subject: Re: Referencing Nested Sequences > > > Thanks , > > I did not expect such a quick response. > Derek, I guess the ".au" postfix gave me away, I'm from Sydney. Some of the > lingo you used might give us all away as a "wierd mob" :) Well aren't we? > I realise that I may have simplified my example to where it lost some of the > general issue. I was hoping/believing that Euphoria would be great for > symbolic manipulations,i.e where you could coalesce sub-sequences into an item > that is part of a larger item, generally rearrange items in a sequence - where > each of these items might be a nested sequence. > > Would this result in is that large 'copying tasks' for each rearrangement ? - Not really. If I understand this ( Robert Craig - can you confirm this?) correctly, altering an element inside a sequence does not mean that the entire sequence is copied to a new RAM location. Internally, a sequence uses pointers to data, like a handle. This, combined with reference counting and garbage collection, means that manipulating a sequence's contents is not all that inefficient. > even though it might just be pushing a item up or down the structure. > That is, you may have just moved an subsequence - but as soon as you set a value > in the "moved" subseqence would Euphoria assume a copy of the entire subsequence > is necessary? > This is perhaps why a sort library function is vital, since > shifting the items manually around and then setting values later would cause > large 'copying' - i.e if the sort was coded outside the library function. You can see the source code for the supplied sort() function in sort.e file. It is really very quick. Here is a short program to demonstrate that the length of a sequence does not greatly influence the speed of changing its elements. ---- include machine.e atom e integer c,l sequence x,y tick_rate(1000) x = repeat({0,1,2,3,4,5,6,7,8,9}, 4) l=20 x = repeat(x,l) y = {{"testdata"}} c = 0 e = time()+10 while e > time() do x[2] = y c += 1 end while ? c --- This just counts the number of assignments done in a 10 second span. Try varying the value of 'l' and you should see that it doesn't change things much. BTW, on my machine I'm getting a count around 21 million. -- Derek