{"id":36618193,"url":"https://github.com/naotsugu/piecetable","last_synced_at":"2026-02-06T17:15:54.070Z","repository":{"id":59982481,"uuid":"535640669","full_name":"naotsugu/piecetable","owner":"naotsugu","description":"Java implementation of PieceTable data structure. ","archived":false,"fork":false,"pushed_at":"2026-01-25T06:24:01.000Z","size":5302,"stargazers_count":18,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-25T21:15:36.690Z","etag":null,"topics":["algorithms","java"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/naotsugu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-09-12T11:46:59.000Z","updated_at":"2026-01-25T06:24:04.000Z","dependencies_parsed_at":"2022-09-25T12:24:02.490Z","dependency_job_id":"607a275e-3c5a-428b-8d51-586bc0fd4e42","html_url":"https://github.com/naotsugu/piecetable","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/naotsugu/piecetable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naotsugu%2Fpiecetable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naotsugu%2Fpiecetable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naotsugu%2Fpiecetable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naotsugu%2Fpiecetable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/naotsugu","download_url":"https://codeload.github.com/naotsugu/piecetable/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naotsugu%2Fpiecetable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29169413,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T16:33:35.550Z","status":"ssl_error","status_checked_at":"2026-02-06T16:33:30.716Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","java"],"created_at":"2026-01-12T09:15:28.533Z","updated_at":"2026-02-06T17:15:54.065Z","avatar_url":"https://github.com/naotsugu.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# piecetable\n\n[![Build](https://github.com/naotsugu/piecetable/actions/workflows/gradle-build.yml/badge.svg)](https://github.com/naotsugu/jpa-fluent-query/actions/workflows/gradle-build.yml)\n\n\nPiece table data structure in Java.\n\nPiece table is a data structure typically used to represent a text document editing.\n\n\n## Operations of piece table\n\n### Initial state\n\nA piece table consists of three columns:\n\n* Which buffer\n* Start index in the buffer\n* Length in the buffer\n\nIn addition to the table, two buffers are used to handle edits:\n\n* `read-only` : A reference to the original text document\n* `append-only` : A buffer to a temporary file\n\n![piecetable1](docs/images/piecetable1.png)\n\n\n### Insert\n\nInserting characters to the text consists of:\n\n* Appending characters to the `read-only` buffer, and\n* Updating the entry in piece table (breaking an entry into two or three)\n\n\n![piecetable2](docs/images/piecetable2.png)\n\n### Delete\n\nSingle character deletion can be one of two possible conditions:\n\n* The deletion is at the start or end of a piece entry, in which case the appropriate entry in piece table is modified.\n* The deletion is in the middle of a piece entry, in which case the entry is split then one of the successor entries is modified as above.\n\n![piecetable3](docs/images/piecetable3.png)\n\n\n## Usage\n\nAdd dependencies.\n\n```kotlin\ndependencies {\n    implementation(\"com.mammb:piecetable:0.6.3\")\n}\n```\n\nThere are three classes.\n\n- PieceTable - Primitive piece table implantation by bytes\n- Document - Text manipulation with row-column number and charset infer\n- TextEdit - Advanced text editing abstraction, with undo/redo, and more\n\nUse `TextEdit` in most cases.\n\n\n### PieceTable\n\n```java\nvar pt = PieceTable.of();\n\npt.insert(0, \"a large text\".getBytes());\npt.insert(8, \"span of \".getBytes());\npt.delete(1, 6);\n\nvar bytes = pt.get(0, (int) pt.length());\nassertEquals(\"a span of text\", new String(bytes));\n```\n\n\n### Document\n\n```java\nvar doc = Document.of();\n\ndoc.insert(0, 0, \"a large text\"); // row:0 col:0\ndoc.insert(0, 8, \"span of \");     // row:0 col:8\ndoc.delete(0, 1, 6);              // row:0 col:1\n\nvar text = doc.getText(0);        // get the text of row:0\nassertEquals(\"a span of text\", text);\n```\n\n\nTo load an existing file, use the following\n\n```java\nvar path = Path.of(\"sample.txt\");\nvar doc = Document.of(path);\n```\n\n\nThe charset is inferred from the loaded file, but can also be specified explicitly.\n\n```java\nvar doc = Document.of(path, Charset.forName(\"xxx\"));\n```\n\n`CharsetMatch` can also be used to customize charset infer.\n\n```java\nCharsetMatch customCharsetMatch = // ...\nvar doc = Document.of(path, customCharsetMatch);\n```\n\n### TextEdit\n\n```java\nvar edit = TextEdit.of();\n\nedit.insert(0, 0, \"a large text\");\nedit.insert(0, 8, \"span of \");\nedit.delete(0, 1, 6);\nassertEquals(\"a span of text\", edit.getText(0));\n\nedit.undo();\nassertEquals(\"a large span of text\", edit.getText(0));\n\nedit.redo();\nassertEquals(\"a span of text\", edit.getText(0));\n```\n\n\n## How to run the example application\n\n```shell\n./gradlew build\ncd examples/fx-editor\n./gradlew run\n```\n\n![screenshot-example](docs/images/screenshot-1.png)\n\nThis example is merely a simple demonstration. For more practical applications, please refer to the following.\n\n## Sample applications using this library\n\n* [min-editor](https://github.com/naotsugu/min-editor)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaotsugu%2Fpiecetable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnaotsugu%2Fpiecetable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaotsugu%2Fpiecetable/lists"}