If Mods think this is not the correct forum for this question, please have it moved where you think is appropriate!

After a lot of Google search I have finally settled on the following data structure:
The piece table method

The piece table method shown in the above link, does not require actual insertions and deletions of data, it is keeping and moving the "pointers".

First buffer will have the original contents of the file and second buffer will be in the appending mode.

That means if a character is to be inserted between pre-existing two characters then the first and the third pointer will be pointing to the two old characters and the second one to the new character residing in the second buffer.

Because we are not deleting the characters we can have unlimited number of undoes!


Does the below design make sense ?
The case I have shown here is of EDITING
/* Below is buffer 1: (the read-only file) */
[abcd efghi ...(upto 80th char)]->[ijklm nop ...(upto 80th char)]->...
 ^        ^
 |        |
 |        |        /*The ever-growing list of pointers*/
[P1, P2, P3, P4, ..., (up to 80th pointer)]->[P1, ..., (up to 80th pointer)]->...
[new data]->
/* Above is buffer 2: (the append-only file) */
  • The first linked list is the read only file containing the original text of the file in question. Each node contains 80 characters (a line)
  • The last linked list is the one in which user will append the changes or the new text.
    I am unable to decide the default size of the nodes here.
  • The linked list in the middle contains pointers which will be pointing to both the other linked lists in cases of insertion and deletions.
    P1 points to the first part of old text and P3 points to last part of old text. And P2 points to the new text which is supposed to replace the text between P1 and P3.

    Is there any other way of representing it better ?