xsl-list
[Top] [All Lists]

Re: [xsl] XQuery/XPath 3.1: Node List to Node Set ("distinct nodes")

2021-12-28 18:10:34


On 28 Dec 2021, at 23:54, Dimitre Novatchev dnovatchev(_at_)gmail(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> 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
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--


<Prev in Thread] Current Thread [Next in Thread>