Test Results for Collate - volume test

eXist Version 1.3.0dev : Revision 8849

3 Tests passed

Examples of Collating sequences. Files are in the database and only the mis-matches are output. There are 500 items in each sequence, with the middle value missing from the second.

Author: Chris Wallace

Epilog

 
let $a := doc("/db/Wiki/UnitTest2/data/seq3.xml")/data 
let $b :=   doc("/db/Wiki/UnitTest2/data/seq4.xml")/data 
return local:merge($a/item,$b/item)         
        

Iterative merge of primary and secondary sequences : Passed

Task where one sequence is the primary seqence, one could iterate through that sequence and look up in the secondary.
XQuery
 
declare  function local:merge($primary, $secondary as item()* ) as item()*  {
for $item in $primary
return
    if (exists($secondary[.=$item]))
    then ()
    else <missing>{$item}</missing>
};

  
Output
<missing>
    <item>250</item>
</missing>
Elapsed Time (ms) 2896

iterative merge of main and secondary : Passed

Task We could test using a qualified expression.
XQuery
 
declare  function local:merge($primary, $secondary as item()* ) as item()*  {
for $item1 in $primary
return
    if (some $item2 in $secondary satisfies $item2 = $item1)
    then ()
    else <missing>{$item1}</missing>
};
   
Output
<missing>
    <item>250</item>
</missing>
Elapsed Time (ms) 1423

Recursive merge of a sequence of elements. : Passed

Task The elements are assumed to be in ascending order.
XQuery
 
declare function local:merge($a, $b  as item()*  )  as item()* {
    if (empty($a) and empty($b))
    then ()
    else if (empty ($b) or $a[1] lt $b[1])
    then (<a>{$a[1]}</a>, local:merge(subsequence($a, 2), $b))
    else  if (empty($a) or $a[1] gt $b[1])
    then  (<b>{$b[1]}</b>, local:merge($a, subsequence($b,2)))           
    else   (local:merge(subsequence($a,2), subsequence($b,2)))
   };

   
Output
<a>
    <item>250</item>
</a>
Elapsed Time (ms) 249