-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d04da30
Showing
27 changed files
with
1,160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_style = space | ||
tab_width = 4 | ||
indent_size = 4 | ||
max_line_length = 120 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[{*.md,LICENSE}] | ||
max_line_length = 80 | ||
trim_trailing_whitespace = false | ||
|
||
[{*.yml,*.yaml,*.json,*.js,*.ts,.prettierrc,*.html,*.css,*.scss}] | ||
indent_size = 2 | ||
tab_width = 2 | ||
|
||
[{*.go}] | ||
# Go uses tabs and gofmt emits them by default. | ||
indent_style = tab | ||
|
||
[{Makefile,.gitmodules}] | ||
# Makefiles and .gitmodules must (!) use tabs. | ||
indent_style = tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: 2 | ||
|
||
updates: | ||
- package-ecosystem: "gomod" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" | ||
|
||
- package-ecosystem: "github-actions" | ||
directory: "/.github/workflows" | ||
schedule: | ||
interval: "daily" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Go | ||
|
||
on: | ||
push: | ||
branches: ["**"] | ||
|
||
jobs: | ||
all-in-one: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: wagoid/commitlint-github-action@v6 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: "1.24" | ||
check-latest: true | ||
- run: go test -json ./... | ||
- run: test -z $(gofmt -l .); gofmt -l . | ||
- run: go build ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# If you prefer the allow list template instead of the deny list, see community template: | ||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore | ||
# | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# Go workspace file | ||
go.work | ||
go.work.sum | ||
|
||
# env file | ||
.env | ||
|
||
.DS_Store | ||
.idea/ | ||
*.iml | ||
.settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"recommendations": [ | ||
"streetsidesoftware.code-spell-checker", | ||
"editorconfig.editorconfig", | ||
"davidanson.vscode-markdownlint", | ||
"sonarsource.sonarlint-vscode", | ||
"wayou.vscode-todo-highlight", | ||
"redhat.vscode-yaml", | ||
"golang.go" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"cSpell.language": "en,de", | ||
"cSpell.words": [ | ||
"commitlint", | ||
"github", | ||
"gomod", | ||
"yannickkirschen" | ||
], | ||
"editor.formatOnSave": true, | ||
"editor.wordWrap": "on", | ||
"editor.rulers": [ | ||
80, | ||
120 | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
{ | ||
"scanSettings": { | ||
"baseBranches": [] | ||
}, | ||
"checkRunSettings": { | ||
"vulnerableCheckRunConclusionLevel": "failure", | ||
"displayMode": "diff", | ||
"useMendCheckNames": true | ||
}, | ||
"issueSettings": { | ||
"minSeverityLevel": "LOW", | ||
"issueType": "DEPENDENCY" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Code of Conduct | ||
|
||
Actually, the author is hungry and does not want to write a novel here. So, | ||
please just act like a normal human and treat others the same way as you want to | ||
be treated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Contributing | ||
|
||
When contributing to this repository, please first discuss the change in the | ||
discussions. | ||
|
||
Please note we have a code of conduct, please follow it in all your interactions | ||
with the project. | ||
|
||
## Coding | ||
|
||
1. Fork the repository. | ||
2. Make your changes on a dedicated branch. | ||
3. Commit your changes according | ||
to [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0). | ||
Please try to only make one commit. Squash/rebase if you made a bunch of | ||
fix-up-commits! Commits will be linted on every push. | ||
4. Open up a pull request. | ||
5. Merge the pull request and make a [release](#release) if required. | ||
|
||
## Release | ||
|
||
Ask the maintainer how to make a release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
MIT No Attribution | ||
|
||
Copyright 2025 Yannick Kirschen | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
software and associated documentation files (the "Software"), to deal in the Software | ||
without restriction, including without limitation the rights to use, copy, modify, | ||
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Graph | ||
|
||
[](https://github.com/yannickkirschen/graphs/actions/workflows/go.yml) | ||
[](https://github.com/yannickkirschen/graphs/releases/) | ||
|
||
A simple graph library written in Go. | ||
|
||
Graphs are represented by an adjacency list combined with ports for each node. | ||
Paths can be found by using recursive depth first search. | ||
|
||
## Caution when using references | ||
|
||
When using reference types as type parameter, always use the same pointer to | ||
reference the same logical object! As the type is being used as key in a map and | ||
compared for equality, this is very important. | ||
|
||
## Usage | ||
|
||
Consider the following simple graph: | ||
|
||
 | ||
|
||
### Define the nodes | ||
|
||
```go | ||
one := graphs.NewNode[int, string](1) | ||
two := graphs.NewNode[int, string](2) | ||
three := graphs.NewNode[int, string](3) | ||
four := graphs.NewNode[int, string](4) | ||
five := graphs.NewNode[int, string](5) | ||
six := graphs.NewNode[int, string](6) | ||
``` | ||
|
||
### Define inner port connections | ||
|
||
```go | ||
one.ConnectBi("a", "b") | ||
two.ConnectBi("a", "b") | ||
two.ConnectBi("a", "c") | ||
three.ConnectBi("a", "b") | ||
four.ConnectBi("a", "b") | ||
five.ConnectBi("a", "b") | ||
five.ConnectBi("a", "c") | ||
six.ConnectBi("a", "b") | ||
``` | ||
|
||
### Initialize the graph | ||
|
||
```go | ||
graph := graphs.NewGraph[int, string]() | ||
graphs.AddNode(one) | ||
graphs.AddNode(two) | ||
graphs.AddNode(three) | ||
graphs.AddNode(four) | ||
graphs.AddNode(five) | ||
graphs.AddNode(six) | ||
``` | ||
|
||
### Define outer node connections | ||
|
||
```go | ||
graphs.ConnectRefBi(1, "b", 2, "a") | ||
graphs.ConnectRefBi(2, "b", 3, "a") | ||
graphs.ConnectRefBi(2, "c", 4, "a") | ||
graphs.ConnectRefBi(3, "b", 5, "b") | ||
graphs.ConnectRefBi(4, "b", 5, "c") | ||
graphs.ConnectRefBi(5, "a", 6, "a") | ||
``` | ||
|
||
#### Find all paths | ||
|
||
```go | ||
paths := graphs.FindRef(1, "b", 4, "b") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package graphs | ||
|
||
import "fmt" | ||
|
||
type Connection[I, P comparable] struct { | ||
FromNode *Node[I, P] | ||
FromPort P | ||
ToNode *Node[I, P] | ||
ToPort P | ||
} | ||
|
||
func (connection *Connection[I, P]) IsSelf() bool { | ||
return connection.FromNode.Equals(connection.ToNode) && connection.FromPort == connection.ToPort | ||
} | ||
|
||
func (connection *Connection[I, P]) EqualNodes() bool { | ||
return connection.FromNode.Equals(connection.ToNode) | ||
} | ||
|
||
func (connection *Connection[I, P]) String() string { | ||
return fmt.Sprintf("%v.%v -> %v.%v", connection.FromNode.id, connection.FromPort, connection.ToNode.id, connection.ToPort) | ||
} | ||
|
||
func NewConnection[I, P comparable](fromNode *Node[I, P], fromPort P, toNode *Node[I, P], toPort P) *Connection[I, P] { | ||
return &Connection[I, P]{fromNode, fromPort, toNode, toPort} | ||
} |
Oops, something went wrong.