{"id":17790935,"url":"https://github.com/cubicdaiya/gonp","last_synced_at":"2025-03-16T14:31:27.679Z","repository":{"id":12939582,"uuid":"15617462","full_name":"cubicdaiya/gonp","owner":"cubicdaiya","description":"diff algorithm in Go","archived":false,"fork":false,"pushed_at":"2023-02-06T15:48:36.000Z","size":76,"stargazers_count":48,"open_issues_count":0,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-27T11:01:26.556Z","etag":null,"topics":["algorithm","diff","go"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cubicdaiya.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}},"created_at":"2014-01-03T19:23:23.000Z","updated_at":"2025-01-12T04:00:52.000Z","dependencies_parsed_at":"2023-02-15T21:30:59.560Z","dependency_job_id":null,"html_url":"https://github.com/cubicdaiya/gonp","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cubicdaiya%2Fgonp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cubicdaiya%2Fgonp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cubicdaiya%2Fgonp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cubicdaiya%2Fgonp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cubicdaiya","download_url":"https://codeload.github.com/cubicdaiya/gonp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243819063,"owners_count":20352812,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["algorithm","diff","go"],"created_at":"2024-10-27T10:48:32.400Z","updated_at":"2025-03-16T14:31:26.789Z","avatar_url":"https://github.com/cubicdaiya.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"![workflow status](https://github.com/cubicdaiya/gonp/actions/workflows/go.yml/badge.svg)\n\n# gonp\n\ngonp is a diff algorithm implementation in Go.\n\n# Algorithm\n\nThe algorithm `gonp` uses is based on \"An O(NP) Sequence Comparison Algorithm\" by described by Sun Wu, Udi Manber and Gene Myers.\nAn O(NP) Sequence Comparison Algorithm(following, Wu's O(NP) Algorithm) is the efficient algorithm for comparing two sequences.\n\n## Computational complexity\n\nThe computational complexity of Wu's O(NP) Algorithm is averagely O(N+PD), in the worst case, is O(NP).\n\n# Getting started\n\n## string difference\n\n```go\ndiff := gonp.New([]rune(\"abc\"), []rune(\"abd\"))\ndiff.Compose()\ned := diff.Editdistance() // ed is 2\nlcs := diff.Lcs() // lcs is \"ab\"\n\nses := diff.Ses()\n// ses is []SesElem{\n//        {e: 'a', t: Common},\n//        {e: 'b', t: Common},\n//        {e: 'c', t: Delete},\n//        {e: 'd', t: Add},\n//        }\n```\n\n## int slice difference\n\n```go\ndiff := gonp.New([]int{1,2,3}, []int{1,5,3})\ndiff.Compose()\ned := diff.Editdistance() // ed is 2\nlcs := diff.Lcs() // lcs is [1,3]\n\nses := diff.Ses()\n// ses is []SesElem{\n//        {e: 1, t: Common},\n//        {e: 2, t: Delete},\n//        {e: 5, t: Add},\n//        {e: 3, t: Common},\n//        }\n```\n\n## unified format difference\n\n```go\ndiff := gonp.New([]rune(\"abc\"), []rune(\"abd\"))\ndiff.Compose()\n\nuniHunks := diff.UnifiedHunks()\ndiff.PrintUniHunks(uniHunks)\n// @@ -1,3 +1,3 @@\n//  a\n//  b\n// -c\n// +d\n```\n\n\n\n# Example\n\n## strdiff\n\n```\n$ make strdiff\ngo build -o strdiff examples/strdiff.go\n$ ./strdiff abc abd\nEditdistance: 2\nLCS: ab\nSES:\n  a\n  b\n- c\n+ d\n```\n\n## intdiff\n\n```\n$ make intdiff\ngo build -o intdiff examples/intdiff.go\n$ ./intdiff\ndiff [1 2 3 4 5] [1 2 9 4 5]\nEditdistance: 2\nLCS: [1 2 4 5]\nSES:\n  1\n  2\n- 3\n+ 9\n  4\n  5\n```\n\n## unistrdiff\n\n```\n$ make unistrdiff\ngo build -o unistrdiff examples/unistrdiff.go\n$ ./unistrdiff abc abd\nEditdistance:2\nLCS:ab\nUnified format difference:\n@@ -1,3 +1,3 @@\n a\n b\n-c\n+d\n```\n\n## uniintdiff\n\n```\n$ make uniintdiff\ngo build -o uniintdiff examples/uniintdiff.go\n$ ./uniintdiff\ndiff [1 2 3 4 5] [1 2 9 4 5]\nEditdistance: 2\nLCS: [1 2 4 5]\nUnified format difference:\n@@ -1,5 +1,5 @@\n 1\n 2\n-3\n+9\n 4\n 5\n```\n\n## unifilediff\n\n```\n$ make unifilediff\ngo build -o unifilediff examples/unifilediff.go\n$ cat a.txt\na\nb\nc\n$ cat b.txt\na\nb\nd\n$ ./unifilediff a.txt b.txt\n@@ -1,3 +1,3 @@\n a\n b\n-c\n+d\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcubicdaiya%2Fgonp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcubicdaiya%2Fgonp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcubicdaiya%2Fgonp/lists"}