> On 28 Dec 2021, at 23:54, Dimitre Novatchev dnovatchev@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
>
> $nodes[index-of($nodes ! generate-id(.), generate-id(.))[1]]
>
> This seems a candidate for "the shortest solution" and it shouldn't be
inefficient, given a good optimizer:
>
It probably also gets a prize for the first practical use case of a filter
expression where the predicate is numeric and has different values for
different nodes in the input sequence.
It's going to be O(n*m) unless index-of() is optimized to use some kind of
index or hash lookup rather than a sequential search. That's assuming that the
expression $nodes ! generate-id(.) gets loop-lifted; if it isn't, then it
becomes O(n*n*m).
Aesthetically, I find generate-id() ugly and it would be nice to avoid it.
Michael Kay
Saxonica
|