Skip to content

A Python implementation of the piece table data structure

License

Notifications You must be signed in to change notification settings

saiguy3/piece_table

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Piece Table

piece-table on TravisCI piece-table on PyPI MIT License badge

About piece_table

Early implementation of the piece table data structure in Python.

A piece table is an efficient data structure to represent a series of edits to a text document. A more detailed discussion can be found here. Inspired by the JavaScript implementation.

Installation

To install the package, run the following:

pip install piece-table

Usage

Current usage is very basic, but will hopefully improve in the future.

Basic use is demonstrated below.

from piece_table import PieceTable

document = PieceTable("Initialize a document with some text.")

document.insert("Add some text to the start of the document. ", 0)

# Delete the inserted text
document.delete(0, 44)

text_sequence = document.get_text()
# text_sequence == "Initialize a document with some text."

sub_string = document[13:21]
# sub_string == "document"

Testing

To test the package, run the following:

python -m unittest discover -s tests

About

A Python implementation of the piece table data structure

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages