Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bcicen/bfstree
Go package providing breadth-first search functions for arbitrary structs
https://github.com/bcicen/bfstree
bfs bfs-search breadth golang-library
Last synced: 25 days ago
JSON representation
Go package providing breadth-first search functions for arbitrary structs
- Host: GitHub
- URL: https://github.com/bcicen/bfstree
- Owner: bcicen
- License: mit
- Created: 2018-01-20T13:09:26.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-03-28T11:57:24.000Z (over 2 years ago)
- Last Synced: 2024-06-19T01:48:48.719Z (5 months ago)
- Topics: bfs, bfs-search, breadth, golang-library
- Language: Go
- Size: 6.84 KB
- Stars: 6
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bfstree
Simple go package providing breadth-first search functions for arbitrary structs
## Usage
```go
package mainimport (
"fmt"
"github.com/bcicen/bfstree"
)type FlightRoute struct {
id int
fromCity string
toCity string
}// FlightRoute implements the bfstree.Edge interface
func (f FlightRoute) From() string { return f.fromCity }
func (f FlightRoute) To() string { return f.toCity }func main() {
tree := bfstree.New(
FlightRoute{0, "New York", "Chicago"},
FlightRoute{1, "New York", "Los Angeles"},
FlightRoute{2, "Los Angeles", "Houston"},
FlightRoute{3, "Chicago", "Tokyo"},
)path, err := tree.FindPath("New York", "Tokyo")
if err != nil {
panic(err)
}fmt.Println(path)
for n, edge := range path.Edges() {
fmt.Printf("flight %d: %s -> %s\n", n+1, edge.From(), edge.To())
}
}
```output:
```
New York->Chicago->Tokyo
flight 1: New York -> Chicago
flight 2: Chicago -> Tokyo
```