gapbuffer
A gap buffer is a simple, array-based data structure used to store and edit text in many text editors. It represents the document as a single contiguous array with a reserved, unused region called the gap at the current cursor position. The text before the gap and the text after the gap together comprise the document content, while the gap holds characters that have not yet been inserted. The gap is defined by two indices: gap_start and gap_end, marking the beginning and end of the unused space.
Edits occur by moving the gap to the desired position and then filling or enlarging it. Moving
Complexity in a gap buffer depends on the operation. Insertion and deletion near the gap are O(1)
Gap buffers are a classical technique used in several editors, including Emacs in its early implementations,