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

Subject: Re: [xsl] XQuery/XPath 3.1: Node List to Node Set ("distinct nodes")
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 29 Dec 2021 00:23:42 -0000
On Tue, Dec 28, 2021 at 4:10 PM Michael Kay mike@xxxxxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

>
>
> > 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).
>
>
Seems BaseX is good enough to do this. I increased the number of nodes in
$nodes 3 times and there was no increase in the evaluation time.



> Aesthetically, I find generate-id() ugly and it would be nice to avoid it.
>

Its name is ugly, yes. A shorter and more meaningful name, like id() or
key() would be much better. Maybe we need a mechanism in XPath 4.0 to
specify global aliases (like a using file... )


Cheers,
Dimitre


>
> Michael Kay
> Saxonica
> 
>
>

-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they write
all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.

Current Thread