Piece table
In computing, a piece table is a data structure typically used to represent a text document while it is edited in a text editor.[src] Initially a reference (or "span") to the whole of the original file is created, which represents the as yet unchanged file.[src] Subsequent inserts and deletes replace a span by combinations of one, two, or three references to sections of either the original document or to a buffer holding inserted text.[src] Typically the text of the original document is held in one immutable block, and the text of each subsequent insert is stored in new immutable blocks.[src] Because even deleted text is still included in the piece table, this makes multi-level or unlimited undo easier to implement with a piece table than with alternative data structures such as a gap buffer.[src] This data structure was invented by J Strother Moore.[src]
In computing, a piece table is a data structure typically used to represent a text document while it is edited in a text editor.[src] Initially a reference (or "span") to the whole of the original file is created, which represents the as yet unchanged file.[src] Subsequent inserts and deletes replace a span by combinations of one, two, or three references to sections of either the original document or to a buffer holding inserted text.[src] Typically the text of the original document is held in one immutable block, and the text of each subsequent insert is stored in new immutable blocks.[src] Because even deleted text is still included in the piece table, this makes multi-level or unlimited undo easier to implement with a piece table than with alternative data structures such as a gap buffer.[src] This data structure was invented by J Strother Moore.[src] The piece table's ordering of rows implicitly describes the ordering of characters to use from the available buffers.[src] I.e., the first row of the piece table (e.g., ) describes the first sequence of characters in the PTD (e.g., PTD indices 0–5).[src] The second row of the piece table (e.g., ) describes the sequence of characters from a possibly different buffer that will immediately follow the characters chosen from the first sequence (e.g., PTD indices 6–10).[src] This continues to the end of the PTD.[src] In the above example, the piece table indicates that the PTD will have 6 + 5 + 6 + 9 = 26 characters.[src] To get the (character) value Index(15) , we first find the entry (row) in the piece table that corresponds to the PTD index 15.[src] The first entry describes characters in PTD indices 0 to 5, the second entry PTD indices 6 to 10, and the 3rd entry PTD indices 11–16.[src] Since the 3rd entry of the piece table corresponds to PTD index 15 (11 ≤ 15 ≤ 16), the 3rd entry is retrieved.[src] The piece table's 3rd entry instructs the program to look for the characters in the "add file" buffer, starting at index 17 in that buffer.[src] The relative index in that entry is PTD_SoughtIndex − PTD_StartIndexOfEntry = 15 − 11 = 4, which is added to the start position of the entry in the buffer to obtain the index of the letter: 4 + 17 = 21.[src] The value of Index(15) is the 21st character of the "add file" buffer, which is the character "o".[src] In general and in the above example, Buffer_IdxOfSoughtChar = PTD_SoughtIndex − PTD_StartIdxOfEntry + Buffer_StartIdxOfEntry 21 = 15 − 11 + 17 SoughtChar = Entry_NameOfBuffer[Buffer_IdxOfSoughtChar] 'o' = AddFileBuf[21] --------------------------- So, 'o' = Index(15) For the buffers and piece table given above, the following PTD is shown: "Lorem " (from piece table entry 1) +"ipsum" (from piece table entry 2) +" dolor" (from piece table entry 3) +" sit amet" (from piece table entry 4) -------------------------- Lorem ipsum dolor sit amet[src]
24 sentences · 24 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Piece table." encyclopegia.org, 2026, https://encyclopegia.org/wiki/piece-table. Accessed 26 November 2026.
Chicago
"Piece table." encyclopegia.org. Accessed November 26, 2026. https://encyclopegia.org/wiki/piece-table.
APA
encyclopegia.org. (2026). Piece table. Retrieved November 26, 2026, from https://encyclopegia.org/wiki/piece-table
Accessed November 26, 2026 · CC BY-SA 4.0 · citation page · JSON