xsl-list
[Top] [All Lists]

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

2021-12-28 17:55:28
Actually, O(n*m) where n is the number of input nodes and m the number of 
output (distinct) nodes. So it's likely to be perfectly viable for large n, but 
not for large m.

Michael Kay
Saxonica

On 28 Dec 2021, at 23:47, Michael Kay mike(_at_)saxonica(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

For a solution that delivers distinct nodes in order of first appearance, my 
preference would be

$nodes => fold-left((), function($all, $this) {if ($all intersect $this) then 
$all else ($all, $this)})

It's likely to be O(n^2) in most implementations, whereas Martin Honnen's 
solution is probably O(n log n) -- but this one is XPath rather than XQuery, 
and feels more elegant.

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>