External sort: Difference between revisions
→{{header|AppleScript}}: Bug fix.
m (→{{header|REXX}}: changed wording in the REXX section header.) |
(→{{header|AppleScript}}: Bug fix.) |
||
Line 118:
if (j > i) then
-- Three-way partitioning: if either value to be swapped is a pivot instance, extend the pivot store
--
--
if (leftValue = pivot) then
set pRight to pRight - integerSize
write pivot as integer to fRef starting at pRight
end if
end if
if (rightValue = pivot) then
set pLeft to pLeft + integerSize
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
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
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
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
set rightList to (read fRef from rightStartByte for maxHalfChunkSize as integer) as list
set b to (count rightList)
|