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. Initially a reference (or 'span') to the whole of the original file is created, which represents the as yet unchanged file. 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.[1]

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. 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.

This data structure was invented by J Strother Moore.[2]

  1. ^ Crowley, Charles (10 June 1998). "Data Structures for Text Sequences - 6.4 The piece table method" (PDF). www.cs.unm.edu. Archived (PDF) from the original on 23 February 2018. Retrieved 26 July 2021.
  2. ^ David Lu. "What's been wrought using the Piece Table?". (discussion)