How would you implement tail efficiently?

后端 未结 4 676
执笔经年
执笔经年 2020-12-14 20:42

What is the efficient way to implement tail in *NIX? I came up (wrote) with two simple solution, both using kind of circular buffer to load lines into circular structure (ar

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-14 21:31

    Read backwards from the end of the file until N linebreaks are read or the beginning of the file is reached.

    Then print what was just read.

    I dont think any fancy datastructures are needed here.

    Here is the source code of tail if you're interested.

提交回复
热议问题