xsl-list
[Top] [All Lists]

Re: Computational complexity of accessing the Nth item in a sequence and in a node-set

2005-01-04 02:23:07
On Mon, 3 Jan 2005 22:41:34 -0000, Michael Kay <mike(_at_)saxonica(_dot_)com> 
wrote:
probably not a direct reference, but by calling a function myLast()
that returns
       $sequence[last]

I want this to be calculated only once. My question was will it be
successful to use the

saxon:memo-function="yes" attribute

on the definition of myLast()

I suspect that's not a good idea. Evaluating $seq[last] is probably much
faster than calculating the hash key to discover that the result is already
stored. Memo functions work best when the arguments are small.

As always, though, the only definitive answer is to measure it.

Thank you, Mike.

From your answer it follows that the hash code is calculated taking
into account all items of the sequence.

This prompts a few other questions I've had for some time:

When a sequence is passed as a parameter, what is actually passed --
its copy or a reference to the sequence?

If there's actually such thing as a reference to a sequence, then why
should calculating the hash key of this reference take longer than
scanning through many items until the last (which may be thousands of
items away)?

Are subsequences shared so that when an item is added at either end
the original sequence is not copied, but a reference to itself is
used?

I know the general answer about this being implementation-dependent,
however Saxon is the only real XSLT 2.0 processor I have at this
moment. I also believe that understanding the principles behind the
answers will help XSLT programmers write better, more efficient XSLT
code units.

Cheers,
Dimitre.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--