{"id":17002665,"url":"https://github.com/johnfercher/go-tree","last_synced_at":"2025-06-17T00:38:37.281Z","repository":{"id":193598138,"uuid":"689060325","full_name":"johnfercher/go-tree","owner":"johnfercher","description":"A generic unbalanced doubly-linked tree implementation.","archived":false,"fork":false,"pushed_at":"2024-02-01T22:17:50.000Z","size":55,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-12T06:29:50.813Z","etag":null,"topics":["data-structures","generics","tree-structure"],"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/johnfercher.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"johnfercher"}},"created_at":"2023-09-08T17:46:20.000Z","updated_at":"2024-01-28T19:39:35.000Z","dependencies_parsed_at":"2024-02-01T23:06:27.876Z","dependency_job_id":"526fc7c8-58e7-4426-ac0e-72ce4f16285e","html_url":"https://github.com/johnfercher/go-tree","commit_stats":null,"previous_names":["johnfercher/tree","johnfercher/go-tree"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/johnfercher/go-tree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnfercher%2Fgo-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnfercher%2Fgo-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnfercher%2Fgo-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnfercher%2Fgo-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johnfercher","download_url":"https://codeload.github.com/johnfercher/go-tree/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnfercher%2Fgo-tree/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260268635,"owners_count":22983601,"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":["data-structures","generics","tree-structure"],"created_at":"2024-10-14T04:28:39.936Z","updated_at":"2025-06-17T00:38:37.256Z","avatar_url":"https://github.com/johnfercher.png","language":"Go","funding_links":["https://github.com/sponsors/johnfercher"],"categories":[],"sub_categories":[],"readme":"# go-tree\n\n[![GoDoc](https://godoc.org/github.com/johnfercher/go-tree?status.svg)](https://godoc.org/github.com/johnfercher/go-tree)\n[![Go Report Card](https://goreportcard.com/badge/github.com/johnfercher/go-tree)](https://goreportcard.com/report/github.com/johnfercher/go-tree)\n[![CI](https://github.com/johnfercher/go-tree/actions/workflows/goci.yml/badge.svg)](https://github.com/johnfercher/go-tree/actions/workflows/goci.yml)\n[![Lint](https://github.com/johnfercher/go-tree/actions/workflows/golangci-lint.yml/badge.svg)](https://github.com/johnfercher/go-tree/actions/workflows/golangci-lint.yml)\n[![Codecov](https://codecov.io/gh/johnfercher/go-tree/branch/main/graph/badge.svg)](https://codecov.io/gh/johnfercher/go-tree)\n[![Visits Badge](https://badges.pufler.dev/visits/johnfercher/go-tree)](https://badges.pufler.dev)\n\n\nA generic unbalanced doubly-linked tree implementation, where you can define which node will be added to each node.\n\n## Installation\n\n* With `go get`:\n\n```bash\ngo get -u github.com/johnfercher/go-tree\n```\n\n## Contributing\n\n| Command         | Description                                      | Dependencies                                                  |\n|-----------------|--------------------------------------------------|---------------------------------------------------------------|\n| `make build`    | Build project                                    | `go`                                                          |\n| `make test`     | Run unit tests                                   | `go`                                                          |\n| `make fmt`      | Format files                                     | `gofmt`, `gofumpt` and `goimports`                            |\n| `make lint`     | Check files                                      | `golangci-lint` and `goreportcard-cli`                        |\n| `make dod`      | (Definition of Done) Format files and check files | Same as `make build`, `make test`, `make fmt` and `make lint` | \n| `make install`  | Install all dependencies                         | `go`, `curl` and `git`                                        |\n| `make examples` | Run all examples                                 | `go`                                                          |\n\n## Features\n### Node\n* [NewNode](https://pkg.go.dev/github.com/johnfercher/go-tree/tree#NewNode)\n* [AddNext](https://pkg.go.dev/github.com/johnfercher/go-tree/tree#Node.AddNext)\n* [Backtrack](https://pkg.go.dev/github.com/johnfercher/go-tree/tree#Node.Backtrack)\n* [Get](https://pkg.go.dev/github.com/johnfercher/go-tree/tree#Node.Get)\n* [GetNexts](https://pkg.go.dev/github.com/johnfercher/go-tree/tree#Node.GetNexts)\n* [GetPrevious](https://pkg.go.dev/github.com/johnfercher/go-tree/tree#Node.GetPrevious)\n* [GetStructure](https://pkg.go.dev/github.com/johnfercher/go-tree/tree#Node.GetStructure)\n* [IsLeaf](https://pkg.go.dev/github.com/johnfercher/go-tree/tree#Node.IsLeaf)\n* [IsRoot](https://pkg.go.dev/github.com/johnfercher/go-tree/tree#Node.IsLeaf)\n* [Filter](https://pkg.go.dev/github.com/johnfercher/go-tree/tree#Node.Filter)\n\n### Tree\n* [New](https://pkg.go.dev/github.com/johnfercher/go-tree/tree#New)\n* [Add](https://pkg.go.dev/github.com/johnfercher/go-tree/tree#Tree.Add)\n* [AddRoot](https://pkg.go.dev/github.com/johnfercher/go-tree/tree#Tree.AddRoot)\n* [Backtrack](https://pkg.go.dev/github.com/johnfercher/go-tree/tree#Tree.Backtrack)\n* [Get](https://pkg.go.dev/github.com/johnfercher/go-tree/tree#Tree.Get)\n* [GetRoot](https://pkg.go.dev/github.com/johnfercher/go-tree/tree#Tree.GetRoot)\n* [GetStructure](https://pkg.go.dev/github.com/johnfercher/go-tree/tree#Tree.GetStructure)\n* [Filter](https://pkg.go.dev/github.com/johnfercher/go-tree/tree#Tree.Filter)\n\n## Example\n\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/johnfercher/go-tree/node\"\n\n\t\"github.com/johnfercher/go-tree/tree\"\n)\n\n// nolint:gomnd,gocritic\nfunc main() {\n\ttr := tree.New[string]()\n\n\ttr.AddRoot(node.New(\"0.0\").WithID(0))\n\n\ttr.Add(0, node.New(\"0.1\").WithID(1))\n\ttr.Add(0, node.New(\"0.2\").WithID(2))\n\n\ttr.Add(1, node.New(\"1.3\").WithID(3))\n\ttr.Add(1, node.New(\"1.4\").WithID(4))\n\n\ttr.Add(2, node.New(\"2.5\").WithID(5))\n\ttr.Add(2, node.New(\"2.6\").WithID(6))\n\n\troot, ok := tr.GetRoot()\n\tfmt.Println(ok)             // true\n\tfmt.Println(root.GetData()) // 0.0\n\n\tnode, ok := tr.Get(3)\n\tfmt.Println(ok)             // true\n\tfmt.Println(node.GetData()) // 1.3\n\n\tstructure, ok := tr.GetStructure()\n\tfmt.Println(ok)        // true\n\tfmt.Println(structure) // (NULL) -\u003e (0), (0) -\u003e (1),  (1) -\u003e (3),  (1) -\u003e (4),  (0) -\u003e (2),  (2) -\u003e (5),  (2) -\u003e (6)\n\n\tnodes, ok := tr.Backtrack(6)\n\tfmt.Println(ok) // true\n\tfor _, node := range nodes {\n\t\tfmt.Println(node.GetData()) // 2.6; 0.2; 0.0\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnfercher%2Fgo-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnfercher%2Fgo-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnfercher%2Fgo-tree/lists"}