External sort: Difference between revisions

m (→‎{{header|REXX}}: changed wording in the REXX section header.)
Line 118:
if (j > i) then
-- Three-way partitioning: if either value to be swapped is a pivot instance, extend the pivot store
-- the pivot store on the destination side and, prepareif tothe swapappropriated theslot valueisn't fromalready the pivot destination, swap its
-- appropriatedcurrent slotcontent instead, and writefor (a copy of) the pivot to that slot. and use the retrieved value instead in the main swap.
if (leftValue = pivot) then
set pRight to pRight - integerSize
set leftValue toif (read fRef from pRight for> integerSizej) as integer)then
write pivot as integer set leftValue to (read fRef starting atfrom pRight for integerSize as integer)
write pivot as integer to fRef starting at pRight
end if
end if
if (rightValue = pivot) then
set pLeft to pLeft + integerSize
set rightValue toif (read fRef from pLeft for< integerSizei) as integer)then
write pivot as integer set rightValue to (read fRef starting atfrom pLeft for integerSize as integer)
write pivot as integer to fRef starting at pLeft
end if
end if
-- Write the values to be swapped to the appropriate places in the file.
Line 150 ⟶ 154:
-- and advance the indices to exclude the pivots from the rest of the sort.
repeat with p from l to pLeft by integerSize
if (j comes after> pLeft) then
write (read fRef from j for integerSize as integer) to fRef as integer starting at p
write pivot to fRef as integer starting at j
Line 161 ⟶ 165:
end repeat
repeat with p from r to pRight by -integerSize
if (i comes before< pRight) then
write (read fRef from i for integerSize as integer) to fRef as integer starting at p
write pivot to fRef as integer starting at i
Line 201 ⟶ 205:
-- Derive a new left list from the next half-chunk of data — unless any of this is already
-- covered by the other list, in which case replace both lists with a single one.
if (leftEndByte comes before< rightStartByte) then
set leftList to (read fRef from i for maxHalfChunkSize as integer) as list
set a to 1
Line 219 ⟶ 223:
if (b < 1) then
set rightStartByte to rightStartByte - maxHalfChunkSize
if (rightStartByte comes after> leftEndByte) then
set rightList to (read fRef from rightStartByte for maxHalfChunkSize as integer) as list
set b to (count rightList)
557

edits