PieceTable

:= {
    original : List(a),
    added : List(a),
    table : List(Entry),
}

Represents a Piece table which is typically used to represent a text document while it is edited in a text editor.

insert : PieceTable(a), { values : List(a), index : U64 } -> PieceTable(a)

Insert values into the table at a given index.

If index is larger than current buffer, appends to end of file.

length : List(Entry) -> U64

Calculate the total length when buffer indexes will be converted to a list.

delete : PieceTable(a), { index : U64 } -> PieceTable(a)

Delete the value at index.

If index is out of range this has no effect.

to_list : PieceTable(a) -> List(a)

Fuse the original and added buffers into a single list.

Entry

:= [Add(Span), Original(Span)]

Represents an index into the original or added buffer.