Merging pre-sorted files without reading everything into memory

后端 未结 2 2121
遥遥无期
遥遥无期 2021-01-03 14:25

I have a list of log files, where each line in each file has a timestamp and the lines are pre-sorted ascending within each file. The different files can have overlapping ti

2条回答
  •  无人及你
    2021-01-03 14:56

    You want to implement a file-based merge sort. Read a line from both files, output the older line, then read another line from that file. Once one of the files is exhausted, output all the remaining lines from the other file.

提交回复
热议问题