{"id":24725570,"url":"https://github.com/begmaroman/go-dag","last_synced_at":"2025-03-22T14:13:38.178Z","repository":{"id":273743534,"uuid":"920750408","full_name":"begmaroman/go-dag","owner":"begmaroman","description":"Directed Acyclic Graph (DAG) implementation in GoLang using generics","archived":false,"fork":false,"pushed_at":"2025-01-22T18:01:15.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-07T08:47:58.881Z","etag":null,"topics":["dag","data-structures","graph","graph-algorithms"],"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/begmaroman.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":"2025-01-22T17:55:41.000Z","updated_at":"2025-01-29T17:23:30.000Z","dependencies_parsed_at":"2025-01-22T18:41:20.162Z","dependency_job_id":null,"html_url":"https://github.com/begmaroman/go-dag","commit_stats":null,"previous_names":["begmaroman/go-dag"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/begmaroman%2Fgo-dag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/begmaroman%2Fgo-dag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/begmaroman%2Fgo-dag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/begmaroman%2Fgo-dag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/begmaroman","download_url":"https://codeload.github.com/begmaroman/go-dag/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244966523,"owners_count":20539797,"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":["dag","data-structures","graph","graph-algorithms"],"created_at":"2025-01-27T13:19:54.426Z","updated_at":"2025-03-22T14:13:38.147Z","avatar_url":"https://github.com/begmaroman.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-dag: A Thread-Safe Directed Acyclic Graph (DAG) Implementation in Go\n\n`go-dag` is a high-performance, thread-safe implementation of Directed Acyclic Graphs (DAGs) in Go. This library is designed to prevent cycles and duplicate entries, ensuring the graph always remains a valid DAG. It uses caching for descendants and ancestors to optimize performance and speed up subsequent operations.\n\n## Features\n\n- **Thread-Safe**: Safe for concurrent use.\n- **Cycle Prevention**: Automatically detects and prevents cycles.\n- **Duplicate Prevention**: Ensures vertices and edges are unique.\n- **Optimized Performance**: Caches descendants and ancestors for faster subsequent calls.\n- **Comprehensive Operations**: Supports adding vertices, edges, transitive reduction, and more.\n\n## Benchmarks\n\n| Operation                                 | Time Taken          |\n|------------------------------------------|---------------------|\n| Add 597,871 vertices and 597,870 edges   | `3.770388s`         |\n| Get descendants (first time)             | `1.578741s`         |\n| Get descendants (subsequent call)        | `0.143887s`         |\n| Get descendants ordered                  | `0.444065s`         |\n| Get children                             | `0.000008s`         |\n| Transitive reduction with caches         | `1.301297s`         |\n| Transitive reduction without caches      | `2.723708s`         |\n| Delete an edge from the root             | `0.168572s`         |\n\n## Installation\n\nTo install the library, use:\n\n```bash\ngo get github.com/begmaroman/go-dag\n```\n\n## Quick Start\n\nHere’s how you can use the `go-dag` library:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\n\t\"github.com/begmaroman/go-dag\"\n)\n\nfunc main() {\n\t// Initialize a new DAG\n\td := dag.NewDAG[int]()\n\n\t// Add vertices\n\tv1, _ := d.AddVertex(1)\n\tv2, _ := d.AddVertex(2)\n\tv3, _ := d.AddVertex(3)\n\n\t// Add edges\n\t_ = d.AddEdge(v1, v2)\n\t_ = d.AddEdge(v1, v3)\n\n\t// Print the graph\n\tfmt.Print(d.String())\n}\n```\n\n## Key Operations\n\n- **Adding Vertices**:\n  ```go\n  vertex, err := d.AddVertex(value)\n  err := d.AddVertexById(id, value)\n  ```\n\n- **Adding Edges**:\n  ```go\n  err := d.AddEdge(fromVertex, toVertex)\n  ```\n\n- **Getting Descendants**:\n  ```go\n  descendants, err := d.GetDescendants(vertex)\n  ```\n\n- **Getting Ancestors**:\n  ```go\n  ancestors, err := d.GetAncestors(vertex)\n  ```\n\n- **Transitive Reduction**:\n  ```go\n  d.ReduceTransitively()\n  ```\n\n## Example\n\nBelow is a simple example showcasing the features of `go-dag`:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/begmaroman/go-dag\"\n)\n\nfunc main() {\n\t// Create a new DAG\n\tgraph := dag.NewDAG[string]()\n\n\t// Add vertices\n\tvA, _ := graph.AddVertex(\"A\")\n\tvB, _ := graph.AddVertex(\"B\")\n\tvC, _ := graph.AddVertex(\"C\")\n\tvD, _ := graph.AddVertex(\"D\")\n\n\t// Add edges\n\t_ = graph.AddEdge(vA, vB)\n\t_ = graph.AddEdge(vA, vC)\n\t_ = graph.AddEdge(vB, vD)\n\n\t// Get descendants\n\tdescendants, _ := graph.GetDescendants(vA)\n\tfmt.Println(\"Descendants of A:\", descendants)\n\n\t// Perform transitive reduction\n\tgraph.ReduceTransitively()\n\tfmt.Println(\"After transitive reduction:\", graph.String())\n}\n```\n\n## Advanced Usage\n\nFor more advanced examples, check the [examples directory](./cmd) or example test files.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.\n\n## Contributing\n\nContributions are welcome! Feel free to submit issues or pull requests to improve this library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbegmaroman%2Fgo-dag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbegmaroman%2Fgo-dag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbegmaroman%2Fgo-dag/lists"}