My task is to sort file which is too large to fit in memory. File contains text lines.
What I did:
- read from original file by parts (of allowed size).
- sorted each part
- saved each sorted part to tempfiles
As I understand next thing i should do is:
- read first lines of each file
- sort them between each other (use local variable to temporarily store it, but I am not sure if it will be below restricted size)
- write first line (as result of sorting) to final file
- now I need to remove line I just wrote from temporary file
- now i need to repeat steps 1-4 until all lines are sorted and "transferred" from temp files to final file
I am most unsure about step 4 - is there a class than can look for a value and then erase line with this value (at that point I won't even know from which file that line came)? I think that this is not a proper way to reach my goal at all. But I need to remove lines which are already sorted. And I can't operate with files' data in memory.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…