Anonymous user
External sort: Difference between revisions
m
→{{header|REXX}}: changed wording in the REXX section header, added/changed whitespace and comments.
m (→{{header|REXX}}: changed wording in the REXX section header, added/changed whitespace and comments.) |
|||
Line 1,273:
<br>The sort work files are then sorted with an external sort, and then merged into one big file.
This particular example uses the DOS '''SORT''' and '''
<lang rexx>/*REXX pgm reads a file, splits into smaller files, sorts 'em, combines into sorted file*/
parse arg FID n lim seed . /*obtain optional arguments from the CL*/
if FID=='' | FID=="," then FID= 'SORT_EXT.OUT' /*name of the output (sorted) file. */
if n=='' | n=="," then n=
if lim=='' | lim=="," then lim=
if datatype(seed, 'W') then call random ,,seed /*Numeric? Then use it as a rand seed.*/
sWork = 'SORTWORK.' /*the filename of the SORTWORK files.*/
Line 1,284:
call srt # /*sort records in all SORTWORK files.*/
call mrg /*merge records in the SORTWORK files.*/
exit
/*──────────────────────────────────────────────────────────────────────────────────────*/
mrg: procedure expose FID sWork; parse arg #
@.= copies('ff'x, 1e5) /*no value should be larger than this. */
call lineout FID, , 1 /*position the output file at rec # 1. */
do j=1 until @.j==@.; call rdr j
end /*j*/ /*but initially just 1 record per file.*/
j=j-1 /*adj. J; read from a non─existent file*/▼
j= j -
do forever;
z= 0
if @.k<<y then do; y=@.k; z=k; end /*Lowest so far? Then mark this as min.*/▼
if @.k==@. then call rdr k /*Not defined? Then read a file record*/
z= k
end
if z==0 then leave /*Any more records? No, close file. */
call lineout FID, @.z /*write the value to the output file. */
call rdr z /*re-populate a value from the # file. */
end /*forever*/ /*keep reading/merging until exhausted.*/
call lineout FID /*close the output file (just in case).*/
'
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
gen: procedure expose #; parse arg m,siz;
# = 0 /*number of SORTWORK.nnn files so far*/
do j=1 for m; #= 1 + j % siz
call lineout 'SORTWORK.'#,
end /*j*/
do k=1 for #; call lineout 'SORTWORK.'#
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
rdr: parse arg a;
/*──────────────────────────────────────────────────────────────────────────────────────*/
srt: procedure expose sWork; parse arg #
do j=1 for #; fn= sWORK || j; 'SORT' fn "/O" fn; end /*j*/; return</lang><br><br>
=={{header|Wren}}==
|