Skip to content

metallidou/Piece-Table

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Piece Table

This is my C++ implementation of the Piece Table data structure, which is mainly used in text editors, as it offers easy undo/redo operations and fast text modifications.

Features

  • Efficient insertions and deletions
  • Undo and redo support
  • Lightweight and simple implementation
  • Works with large texts efficiently
  • Includes unit tests with Catch2

Build & Run

This project uses a build script (build.sh) to automate building with CMake.

Steps

  1. Make the script executable
chmod +x build.sh
  1. Run script to build project
./build.sh
  1. Run main program
./build/main
  1. Run unit tests
./build/unit_test

Usage

The main program demonstrates basic operations with the Piece table

int main()
{
    std::string text = "abcdef";
    PieceTable p(text);

    // Print text
    std::cout << "Text is: " << p.getText() << std::endl;

    // Insert text
    p.insertPiece(6, "gh");
    std::cout << "Text after insert: " << p.getText() << std::endl;

    // Erase text
    p.erasePiece(1, 3);
    std::cout << "Text after erase: " << p.getText() << std::endl;

    // Undo
    p.undoPiece();
    std::cout << "Text after undo: " << p.getText() << std::endl;

    // Redo
    p.redoPiece();
    std::cout << "Text after redo: " << p.getText() << std::endl;

    // Replace text
    p.replacePiece(1, 3, "BC");
    std::cout << "Text after replace: " << p.getText() << std::endl;

    return 0;
}

Testing

Unit tests are implemented using Catch2, a modern C++ testing framework, which is simple and efficient.

About

A C++ implementation of the Piece Table data structure, designed for high-speed text processing and editing.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors