Virtual Pascal

Classic Object Pascal for free

Sort Unit ... based on the original TurboSort ... anyone interested?

G'day Folks,

Yonks ago, I modified the old Turbo Sort as it then stood at version 4, to work under VP. I've called the "VP" version ... TurboSrt4x.

For those who don't remember it; it uses an internal Quicksort but will extend to a sort work file without any other coding needed by the caller.

I have tested the version I have, on 10million records of both 50byte & 256bytes and it runs quite quickly eg: ~14 mins on a P4...
Other than disk space & time, it ought to be able to sort a reasonably unlimited number of records since it was designed to page it all to the sort work file. The records to be sorted can be quite large ...48K if you want!

It expects fixed-length records but you can sort variable length strings by simply specifying the longest string as the record length (including any length bytes!! ...ie: 256 for a standard pascal string (not 255!)). If you know *for certain*, your strings will not exceed say 128 bytes, you can make it more efficient by specifying that length (128) + 1 (length byte), so 129!

Just like the original Turbo Sort, it needs you to specify 5 routines -
INP & SortRelease - to pass to the sort, the records you want sorted
OUP & SortReturn - to receive back the sorted records from the unit
& SortXbeforeY - which you define to indicate to the sort that record X should sort before record Y.
(SortXbeforeY was called LESS in the original TurboSort).

You define the addresses of these routines (once) in pointers provided by the sort so it can call the routines when needed. ie: There is some minor setup needed ... or the Unit doesn't know where/how to call back to you.

NB: You can use whatever criteria you like in the routine SortXbeforeY eg: multiple sort fields. All the sort wants to know is whether you want X sorted first - or the other way around .. it does the rest.

Maybe someone else has done this already? .. but I don't recall seeing one..

Cheers,
Barry

Views: 44

Reply to This

© 2021   Created by Allan Mertner.   Powered by

Report an Issue  |  Terms of Service