Re: [cc65] Sorting large files

Date view Thread view Subject view

From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2002-08-26 22:47:59


Hi!

On Mon, Aug 26, 2002 at 01:12:32PM -0700, Shawn Jefferson wrote:
> Just hoping to get a few suggestions as to how to sort a potentially very
> large file (could be up to 90k) and each record is about 27 bytes long.

Divide the data into several parts, each part small enough to fit in memory.
Sort the data in memory (qsort is a library routine), then write it to a file.
After having sorted each part, open all files plus the target file. Combine
the files while maintaining sort order by reading records from the input files
and writing the largest/smallest record to the target file.

Possible optimizations:

  1. Make the number of parts as small as possible. This means that you have
     les input files later.

  2. Keep the last part in memory after sorting it. Needs some special casing
     but saves a complete write/read cycle for one of the parts.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz_at_musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2002-08-26 22:48:01 CEST