{"id":14966089,"url":"https://github.com/titsuki/raku-algorithm-zhangshasha","last_synced_at":"2026-01-22T19:48:48.609Z","repository":{"id":80481484,"uuid":"260928219","full_name":"titsuki/raku-Algorithm-ZhangShasha","owner":"titsuki","description":"Tree edit distance between trees","archived":false,"fork":false,"pushed_at":"2020-05-04T23:55:39.000Z","size":16,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-15T09:35:22.342Z","etag":null,"topics":["edit","perl6","raku","tree","zhangshasha"],"latest_commit_sha":null,"homepage":"","language":"Raku","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"artistic-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/titsuki.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","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":"2020-05-03T13:34:53.000Z","updated_at":"2023-02-16T19:32:40.000Z","dependencies_parsed_at":"2023-03-01T05:45:51.486Z","dependency_job_id":null,"html_url":"https://github.com/titsuki/raku-Algorithm-ZhangShasha","commit_stats":{"total_commits":11,"total_committers":1,"mean_commits":11.0,"dds":0.0,"last_synced_commit":"8dce135c0905fcd6ccb1386eebd6c9ee0a4afaee"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/titsuki%2Fraku-Algorithm-ZhangShasha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/titsuki%2Fraku-Algorithm-ZhangShasha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/titsuki%2Fraku-Algorithm-ZhangShasha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/titsuki%2Fraku-Algorithm-ZhangShasha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/titsuki","download_url":"https://codeload.github.com/titsuki/raku-Algorithm-ZhangShasha/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248060494,"owners_count":21041168,"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":["edit","perl6","raku","tree","zhangshasha"],"created_at":"2024-09-24T13:35:48.700Z","updated_at":"2026-01-22T19:48:48.599Z","avatar_url":"https://github.com/titsuki.png","language":"Raku","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/titsuki/raku-Algorithm-ZhangShasha.svg?branch=master)](https://travis-ci.org/titsuki/raku-Algorithm-ZhangShasha)\n\nNAME\n====\n\nAlgorithm::ZhangShasha - Tree edit distance between trees\n\nSYNOPSIS\n========\n\n```perl6\nuse Algorithm::ZhangShasha;\n\nmy class SimpleHelper does Algorithm::ZhangShasha::Helpable[Algorithm::ZhangShasha::Node] {\n    method delete-cost(Algorithm::ZhangShasha::Node $this --\u003e Int) {\n        1;\n    }\n\n    method insert-cost(Algorithm::ZhangShasha::Node $another --\u003e Int) {\n        1;\n    }\n\n    method replace-cost(Algorithm::ZhangShasha::Node $this, Algorithm::ZhangShasha::Node $another --\u003e Int) {\n        $another.content eq $this.content ?? 0 !! 1;\n    }\n\n    method children(Algorithm::ZhangShasha::Node $node) {\n        $node.children\n    }\n}\n\nmy constant $ZN = 'Algorithm::ZhangShasha::Node';\n\nmy $root1 = ::($ZN).new(:content(\"f\"))\\\n                   .add-child(::($ZN).new(:content(\"d\"))\\\n                                     .add-child(::($ZN).new(:content(\"a\")))\\\n                                     .add-child(::($ZN).new(:content(\"c\"))\\\n                                                       .add-child(::($ZN).new(:content(\"b\")))\\\n                                               )\\\n                             )\\\n                   .add-child(::($ZN).new(:content(\"e\")));\n\nmy $root2 = ::($ZN).new(:content(\"f\"))\\\n                   .add-child(::($ZN).new(:content(\"c\"))\\\n                                     .add-child(::($ZN).new(:content(\"d\"))\\\n                                                       .add-child(::($ZN).new(:content(\"a\")))\\\n                                                       .add-child(::($ZN).new(:content(\"b\")))\\\n                                               )\\\n                             )\\\n                   .add-child(::($ZN).new(:content(\"e\")));\n\nmy Algorithm::ZhangShasha::Tree[Algorithm::ZhangShasha::Node] $tree1 .= new(:root($root1), :helper(SimpleHelper.new));\nmy Algorithm::ZhangShasha::Tree[Algorithm::ZhangShasha::Node] $tree2 .= new(:root($root2), :helper(SimpleHelper.new));\n\nsay $tree1.tree-distance($tree2).key; # 2\nsay $tree1.tree-distance($tree2).value; # ({op =\u003e KEEP, pair =\u003e 1 =\u003e 1} {op =\u003e KEEP, pair =\u003e 2 =\u003e 2} {op =\u003e DELETE, pair =\u003e 3 =\u003e 2} {op =\u003e KEEP, pair =\u003e 4 =\u003e 3} {op =\u003e INSERT, pair =\u003e 4 =\u003e 4} {op =\u003e KEEP, pair =\u003e 5 =\u003e 5} {op =\u003e KEEP, pair =\u003e 6 =\u003e 6})\n```\n\nDESCRIPTION\n===========\n\nAlgorithm::ZhangShasha is an implementation for efficiently computing tree edit distance between trees.\n\nMETHODS of Algorithm::ZhangShasha::Tree\n---------------------------------------\n\n### BUILD\n\nDefined as:\n\n```perl6\nsubmethod BUILD(NodeT :$!root!, Algorithm::ZhangShasha::Helpable :$!helper!)\n```\n\nCreates an `Algorithm::ZhangShasha::Tree` instance.\n\n  * `$!root` is the root node of the tree\n\n  * `$!helper` is the helper class that implements four methods: `delete-cost`, `insert-cost`, `replace-cost`, `children`. If you want to combine 3rd-party node representation (e.g., `DOM::Tiny`), you should define a custom helper. (See `t/01-basic.t`. It implements an exmple for `DOM::Tiny`.)\n\n### size\n\nDefined as:\n\n```perl6\nmethod size(--\u003e Int)\n```\n\nReturns the size of the tree.\n\n### tree-distance\n\nDefined as:\n\n```perl6\nmethod tree-distance(Algorithm::ZhangShasha::Tree $another --\u003e Pair)\n```\n\nReturns a `Pair` instance that has the optimal edit distance and the corresponding operations (e.g., DELETE(3,2)) between the two trees. Where `.key` has the distance and `.value` has the operations.\n\nAUTHOR\n======\n\nItsuki Toyota \u003ctitsuki@cpan.org\u003e\n\nCOPYRIGHT AND LICENSE\n=====================\n\nCopyright 2020 Itsuki Toyota\n\nThis library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.\n\nThis algorithm is from\n\n  * [0] Zhang, Kaizhong, and Dennis Shasha. \"Simple fast algorithms for the editing distance between trees and related problems.\" SIAM journal on computing 18.6 (1989): 1245-1262.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftitsuki%2Fraku-algorithm-zhangshasha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftitsuki%2Fraku-algorithm-zhangshasha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftitsuki%2Fraku-algorithm-zhangshasha/lists"}