{"id":13929925,"url":"https://github.com/fako1024/topo","last_synced_at":"2025-06-29T06:11:44.479Z","repository":{"id":57501120,"uuid":"82682450","full_name":"fako1024/topo","owner":"fako1024","description":"Dependency resolution based on topological sort of a directed graph (for arbitrary types)","archived":false,"fork":false,"pushed_at":"2024-06-25T12:58:19.000Z","size":30,"stargazers_count":12,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-26T19:36:38.835Z","etag":null,"topics":["dependency-graph","dependency-resolution","graphs","sorting-algorithms","topological-sort"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fako1024.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":"2017-02-21T13:23:49.000Z","updated_at":"2024-06-25T12:58:42.000Z","dependencies_parsed_at":"2024-01-17T05:25:09.823Z","dependency_job_id":"94819f35-e08c-48e1-98b3-f174445696b6","html_url":"https://github.com/fako1024/topo","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/fako1024/topo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fako1024%2Ftopo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fako1024%2Ftopo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fako1024%2Ftopo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fako1024%2Ftopo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fako1024","download_url":"https://codeload.github.com/fako1024/topo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fako1024%2Ftopo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262545043,"owners_count":23326665,"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":["dependency-graph","dependency-resolution","graphs","sorting-algorithms","topological-sort"],"created_at":"2024-08-07T18:02:37.447Z","updated_at":"2025-06-29T06:11:44.463Z","avatar_url":"https://github.com/fako1024.png","language":"Go","funding_links":[],"categories":["others"],"sub_categories":[],"readme":"# Topological Sort for arbitrary slices\n\n[![Github Release](https://img.shields.io/github/release/fako1024/topo.svg)](https://github.com/fako1024/topo/releases)\n[![GoDoc](https://godoc.org/github.com/fako1024/topo?status.svg)](https://godoc.org/github.com/fako1024/topo/)\n[![Go Report Card](https://goreportcard.com/badge/github.com/fako1024/topo)](https://goreportcard.com/report/github.com/fako1024/topo)\n[![Build/Test Status](https://github.com/fako1024/topo/workflows/Go/badge.svg)](https://github.com/fako1024/topo/actions?query=workflow%3AGo)\n\nIntroduction\n------------\n\nThe topo package implements a topological sort algorithm to facilitate dependency resolution between elements of arbitrary data types.\nThe topo/graph package provides a directed graph representation for arbitrary data types to perform the actual sort process by describing elements as nodes / vertices and dependencies as links / arcs between these elements.\n\nInstallation and usage\n----------------------\n\nThe import path for the package is *github.com/fako1024/topo*.\nTo install it, run:\n\n    go get github.com/fako1024/topo\n\nAPI summary\n-----------------\n\nThe API of the topo package is fairly straight-forward. The following generics-based types / methods are exposed:\n\n```Go\n// Dependency represents a dependency between one Type and another\ntype Dependency[T comparable] struct {\n\tChild  T\n\tParent T\n}\n\n// Dependencies represents a list of dependencies\ntype Dependencies[T comparable] []Dependency[T]\n\n// String tries to stringify a dependency. If the type of the dependency fulfills\n// the Stringer interface, it will use its String() method, otherwise it will try\n// to format the variable otherwise\nfunc (d Dependency[T]) String() string\n\n// Sort performs a topological sort on a slice and constructs a directed graph (using the\n// dependency constraints) and finally converts back the resulting object list to the\n// original slice (sort in place)\nfunc Sort[T comparable](data graph.Objects[T], deps Dependencies[T]) (err error)\n\n```\nIn order to perform a dependency resolution, first a slice or array containing all elements to be sorted and a list of all dependencies have to be created.\nAfterwards, the actual Sort() call can be performed, causing the original slice to be sorted in-place so as to satisfy all dependencies.\nNote: Sort() is a stable sort algorithm, hence the actual order of elements in the output will be deterministic. A detailed, yet simple example can be found below.\n\nLicense\n-------\n\nThe topo and topo/graph packages are licensed under the Apache License 2.0. Please see the LICENSE file for details.\n\nExample\n-------\n\n```Go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"github.com/fako1024/topo\"\n)\n\n// List of all simple strings (to be sorted)\nvar stringsToSort = []string{\n\t\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\",\n}\n\n// List of dependencies\nvar stringDependencies = []topo.Dependency[string]{\n\t{Child: \"B\", Parent: \"A\"},\n\t{Child: \"B\", Parent: \"C\"},\n\t{Child: \"B\", Parent: \"D\"},\n\t{Child: \"A\", Parent: \"E\"},\n\t{Child: \"D\", Parent: \"C\"},\n}\n\nfunc main() {\n\n\t// Perform topological sort\n\tif err := topo.Sort(stringsToSort, stringDependencies); err != nil {\n\t\tfmt.Printf(\"Error performing topological sort on slice of strings: %s\\n\", err)\n\t\tos.Exit(1)\n\t}\n\n\t// Print resulting Slice in order\n\tfmt.Println(\"Sorted list of strings:\", stringsToSort)\n\tfmt.Println(\"The following dependencies were taken into account:\")\n\tfor _, dep := range stringDependencies {\n\t\tfmt.Println(dep)\n\t}\n}\n```\n\nThis example will generate the following output:\n\n```\nSorted list of strings: [E A C D B F G H]\nThe following dependencies were taken into account:\nB depends upon A\nB depends upon C\nB depends upon D\nA depends upon E\nD depends upon C\n```\n\nAdditional examples can be found in the *_example_test.go files.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffako1024%2Ftopo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffako1024%2Ftopo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffako1024%2Ftopo/lists"}