Skip to content

Instantly share code, notes, and snippets.

@xquery
Created February 8, 2019 09:34
Show Gist options
  • Save xquery/5477c078e6d3208a2f74a74018715b17 to your computer and use it in GitHub Desktop.
Save xquery/5477c078e6d3208a2f74a74018715b17 to your computer and use it in GitHub Desktop.
example topo sort in xquery
declare function local:topo-sort($unsorted, $sorted ) {
if (empty($unsorted)) then $sorted
else
let $allnodes := $unsorted [ every $id in depends/@id satisfies $id = $sorted/@id]
return
if ($allnodes) then
local:topo-sort( $unsorted except $allnodes, ($sorted, $allnodes ))
else ()
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment