|
|||||||
V119 - Part IIHaving considered how to use V119 to sort variables that can be held in memory we can now move on to sorting more records than can be held in memory at one time. When sorting more records that will fit into memory the system cannot rely on a straightforward insertion or bubble sort. Rather it must be able to sort chunks of the data, write out the sorted chunks to a file and then sort this set of sorted chunks. The way in which AREV sorts large amounts of data is to firstly open a sort file then sort a block of data. It then appends this sorted block of data to the opened sort file. It continues looping in this way, retrieving a block, sorting, appending until all records are processed. It then merges all of the chunks into one, doubling the sort file size as the sorted data is put at the beginning and the older information is put into the scratch area above. When this process has been completed ("Finalising Sort") it then goes into another loop, reading the sorting keys in blocks until they are all gone. Finally it deletes the sort file. So to accommodate this, V119 must be able to be called to open a file, sort records, write records, sort the file, get the sorted ids and delete the file. Naturally it can do these things! To recap, V119 is called with six parameters, viz CALL V119( ACTION, FILE, ORDER, JUST, DATA, FLAG). To accomplish all of the above, the following calls are made Initialise (Open the sort file) ACTION = "I" FILE = sort file name including path specification ORDER, JUST, DATA null FLAG = Returns true for OK, false for file open failure. Sort (Sort the data) ACTION = "S" FILE = "" Rest as documented in Issue 7 Write (Append the data to the sort file) ACTION = "W" FILE = sort file name including path specification ORDER, JUST, DATA null FLAG = Returns true for OK, false for write failure. Merge (Combine and sort the sort file) ACTION = "M" FILE = sort file name including path specification ORDER, JUST, DATA null FLAG = Returns true for OK, false for merge failure. Loop (Returns the next batch of sorted keys) ACTION = "L" FILE = sort file name including path specification ORDER, JUST null DATA = Key list FLAG = Returns true for OK, false for read failure. Delete (Remove the sort file) ACTION = "D" FILE = sort file name including path specification ORDER, JUST, DATA null FLAG = Returns true for OK, false for delete failure. Representing the above explanation as pseudocode we would have 0001 CALL V119("I") ; * Initialise 0002 LOOP 0003 UNTIL RECORDS EXHAUSTED 0004 BUILD CHUNK 0005 CALL V119("S") ; * Sort 0006 CALL V119("W") ; * Append 0007 REPEAT 0008 CALL V119("M") ; * Merge 0009 LOOP 0010 UNTIL RECORDS EXHAUSTED 0011 CALL V119("L") ; * Get IDS PROCESS IDS 0012 REPEAT 0013 CALL V119("D") ; * Delete file (Volume 1, Issue 8, Pages 4,9) |
|||||||
| |||||||