V119 - Part II
Published By | Date | Version | Knowledge Level | Keywords |
---|---|---|---|---|
Sprezzatura Ltd | 01 JAN 1990 | 1.15+ | EXPERT | V119, SORT |
Having 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
CALL V119("I") ; * Initialise LOOP UNTIL RECORDS EXHAUSTED BUILD CHUNK CALL V119("S") ; * Sort CALL V119("W") ; * Append REPEAT CALL V119("M") ; * Merge LOOP UNTIL RECORDS EXHAUSTED CALL V119("L") ; * Get IDS PROCESS IDS REPEAT CALL V119("D") ; * Delete file
(Volume 1, Issue 8, Pages 4,9)