Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/g4s8/go-graph
Graph common functions for Go
https://github.com/g4s8/go-graph
algorithm go graph
Last synced: 3 days ago
JSON representation
Graph common functions for Go
- Host: GitHub
- URL: https://github.com/g4s8/go-graph
- Owner: g4s8
- License: mit
- Created: 2022-05-27T15:13:59.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-06-23T06:52:52.000Z (over 2 years ago)
- Last Synced: 2024-06-21T03:16:53.267Z (5 months ago)
- Topics: algorithm, go, graph
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
This go library provides packages with functions for
common graph operations. It doesn't provide graph data structures.
It's designed to be structure agnostic,
it depends only on required API for each operation declared as interface
(similar to standard Go `sort` package).[![CI](https://github.com/g4s8/go-graph/actions/workflows/go.yml/badge.svg)](https://github.com/g4s8/go-graph/actions/workflows/go.yml)
[![GoDoc](https://godoc.org/github.com/g4s8/go-graph?status.svg)](https://godoc.org/github.com/g4s8/go-graph)## Packages
### Search
Package search provides graph search operations:
- `DepthFirstSearch(Graph g, v int, visitor Visitor)` - implements DFS stack-based
algorithm for graph `g` from vertex `v` using `visitor`.
- `BreathFirstSearch(g Graph, v int, visitor Visitor)` - implements BFS queue-based
algorithm for graph `g` from vertex `v` using `visitor`.
- `HasCicle(g Graph)` - detects if graph `g` has any cicle.
- `SimplePaths(g Graph, from, to int)` - finds all simple paths (without cicles)
in graph `g` from vertex `from` to `to`.Graph type for `search` package should be able to say its size of vertices and edges,
and iterate all neighors for each vertex:
```go
type Graph interface {
// Size of vertices and edges
Size() (vertices, edges int)// Neighbors of vertex
Neighbors(v int) []int
}
```The `search` package provides standard visitors for DFS and BFS like:
- `NewFullVisitor(Graph)` which allows to visit all vertices
- `NewShortPathVisitor(g Graph, vertex int)` which stops when destination `vertex`
is visited.Users are free to implement custom visitor as `Visitor` interface.