Skip to content

Instantly share code, notes, and snippets.

@dscape
Created September 8, 2010 10:47
Show Gist options
  • Save dscape/569952 to your computer and use it in GitHub Desktop.
Save dscape/569952 to your computer and use it in GitHub Desktop.
(: better approach as allows you to use xdmp:estimate :)
declare function local:partition-range($list-size, $nr-partitions) {
let $m := if ($nr-partitions > $list-size)
then $list-size
else $nr-partitions,
$step := ceiling( $list-size div $m )
return
for $i in (1 to $m)
let $s := xs:integer( 1 + ( ( $i - 1 ) * $step ) )
let $f := xs:integer( $s + $step - 1 )
return <partition start={$s} end="{$f}"/> };
local:partition-range( 10, 3 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment