home *** CD-ROM | disk | FTP | other *** search
- KSORT Copyright (c) Josh Greifer 1991
-
- This program allows sorting of text files of any size up to 20Mb, or one
- million lines, up to 30 times faster than DOS sort.com.
-
- The syntax is identical to DOS sort.com, including the /R and /+ switches. In
- addition you can specify input and output files instead of using it as a pipe,
- turn case sensitivity on, ignore leading white space in the sort, display
- messages during long sorts, and specify a line buffer smaller than the default
- 16k lines if you don't have enough RAM.
-
- The algorithm used is D.E.Knuth's partition-exchange sort, which is a
- double-ended Quicksort (i.e. sorting is done from both ends of the array).
-
- The algorithm is in Knuth's "The Art of Computer Programming",
- Volume 3, "Sorting and Searching", Section 5.2.2, p. 117.
-
- Besides being much faster than most qsort() implementations in commercial
- C libraries, it uses no stack, so it won't cause a stack overflow on nasty
- files (such as reverse-ordered files).
-
- The algorithm drops through to a enhanced insertion sort (bubble sort) at
- a user-specified point. If the the threshold is, say, 50, then the last 50
- lines to be sorted will be insertion-sorted. The threshold is set with the
- /I switch. If it's less than 1, no insertion sort takes place. If it's
- set to a value greater than the buffer size, the entire sort is done using
- the insertion sort.
-
- The program is written in Microsoft C 6.0 -- remove the underscores before
- the "_huge" keyword, and it should compile with 5.1. You MUST use the
- /AC (Compact Model) switch.
-
- For a blindingly fast version that sorts small (< 100k) files, get rid
- of the halloc() call, and reduce MAXARRAYSIZE to 16382. Now compile for
- the Small Model /AS.
-
- The function ksort() in the source uses goto's and labels. These match
- Knuth's Q algorithm exactly. It's not too hard to rewrite in assembler --
- it looks more like assembler than C, anyway!
-
- The program will create temporary files if necessary, and then merge them.
-
- Remember, ksort is meant to replace DOS sort.com, so it defaults to
- "silent" behaviour, and should be used as a pipe:
-
- type bigfile.txt | ksort > bigfile.srt
-
- Alternatively you can use it like this:
-
- ksort bigfile.txt bigfile.srt
-
- or like this:
-
- ksort bigfile.txt
-
- which will convert the file "in place", deleting the unsorted version.
-
- The switches are summarised below: (Case Sensitive)
-
- Usage: ksort [/R] [/+<column>] [/N] [/S] [/v|V] [/B<size>] [infile] [outfile]
-
- option description default
- -----------------------------------------------------------
- R - reverse sort (off)
- +<column> - start sort at <column> (1)
- N - Don't ignore case (off)
- S - Skip and trim leading white space (off)
- v - verbose -- screen messages (off)
- V - Very verbose -- more screen messages (off)
- I<lines> - Insertion Sort threshold (see above) (0)
- B<lines> - Buffer size (number of lines) max 64000 (16000)
-
-