Concept

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. 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. For this description, we use buffer as the immutable block to hold the contents. A piece table consists of three columns: Which buffer Start index in the buffer Length in the buffer In addition to the table, two buffers are used to handle edits: "Original buffer": A buffer to the original text document. This buffer is read-only. "Add buffer": A buffer to a temporary file. This buffer is append-only. Definition: Index(i): return the character at position iTo retrieve the i-th character, the appropriate entry in a piece table is read. Given the following buffers and piece table: To access the i-th character, the appropriate entry in the piece table is looked up. For instance, to get the value of Index(15), the 3rd entry of piece table is retrieved. This is because the 3rd entry describes the characters from index 12 to 17 (the first entry describes characters in index 0 to 5, the next one is 6 to 11). The piece table entry instructs the program to look for the characters in the "add file" buffer, starting at index 18 in that buffer. The relative index in that entry is 15-12 = 3, which is added to the start position of the entry in the buffer to obtain index of the letter: 3+18 = 21.

About this result
This page is automatically generated and may contain information that is not correct, complete, up-to-date, or relevant to your search query. The same applies to every other page on this website. Please make sure to verify the information with EPFL's official sources.

Graph Chatbot

Chat with Graph Search

Ask any question about EPFL courses, lectures, exercises, research, news, etc. or try the example questions below.

DISCLAIMER: The Graph Chatbot is not programmed to provide explicit or categorical answers to your questions. Rather, it transforms your questions into API requests that are distributed across the various IT services officially administered by EPFL. Its purpose is solely to collect and recommend relevant references to content that you can explore to help you answer your questions.