Skip to content

A TypeScript implementation of the piece table data structure with red-black tree, multiple buffered and optimized by for line model, inspired by VSCode.

License

Notifications You must be signed in to change notification settings

Bistard/piece-table

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

A TypeScript implementation of the piece table data structure with red-black tree, multiple buffered and optimized by for line model.

The repository is almost rewritten by myself from the VSCode's piece-table version. Almost nothing new except more readable coding styles and comments.

What Is Special

  1. The piece table is written using red-black tree as the balanced binary tree.
  2. The piece table may handle all the possible end-of-line cases correctly.
  3. If you are interest in more details about the idea, see the following link from the blog of VSCode.

How To Use

You may use PieceTableBuilder to build PieceTable for yourself as following:

function buildPieceTable(contents: string[], normalizationEOL?: boolean, defaultEOL?: EndOfLineType, force?: boolean): IPieceTable {
    const builder = new PieceTableBuilder();
    for (const content of contents) {
        builder.receive(content);
    }
    builder.build();
    return builder.create(normalizationEOL, defaultEOL, force);
}

How to Test

npm run test

About

A TypeScript implementation of the piece table data structure with red-black tree, multiple buffered and optimized by for line model, inspired by VSCode.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published