What is best data structure suitable to implement editor like notepad?

后端 未结 6 758
抹茶落季
抹茶落季 2021-01-31 12:15

Which data structure/s is used in implementation of editors like notepad. This data structure should be extensible, and should support various features like edition, deletion, s

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-31 12:40

    Wikipedia says many editors use a Gap Buffer. It is basically an array with an unused space in the middle. The cursor sits just before the gap, so deletion and insertion at the cursor is O(1). It should be pretty easy to implement.

    Looking at the source code of Notepad++ (as Chris Ballance suggested in this thread here) shows that they also use a gap buffer. You could get some implementation ideas from that.

提交回复
热议问题