|Perl: the Markov chain saw|
(tye)Re: Sorting data that don't fit in memoryby tye (Sage)
|on Jan 24, 2001 at 19:40 UTC||Need Help??|
See numbers OK; Re: sorting comma separated value file for an example of how to efficiently sort (in terms of memory use and CPU time). You use two arrays, not an array of tiny arrays. Though I don't think you'll end up using this. (:
However, I don't want to sort on the remainder of the string as it is now.
The remainder of the string only enters into it if the first part is the same. Without sorting on the remainder of the string, the order for records with the same 16-bit integer will be "random". So you lose nothing by sorting on that extra data (other than the time involved in comparing those few extra bytes, which seems a net win considering the memory that can be saved).
But you can save a ton of memory by not storing any of your records in memory as follows:
Personally I'd just figure out how many records you can sort using this modification and sort that many, write the sorted list out. Repeat with a new output file until you have, oh, 64 output files or no more data. Then merge the 64 output files into one. Repeat until you have 64 merged files or no data. Merge the merged files.
For merging I'd use a heap (an efficient way of inserting new items into a partially sorted list such that you can efficiently always pull out the "first" item from the list).
Let me know if you need more details but I suspect the several references already mentioned should cover this.- tye (but my friends call me "Tye")