Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brianpursley/sorting-network-go
A Go utility for checking and rendering sorting networks
https://github.com/brianpursley/sorting-network-go
comparison-network golang sorting-algorithms sorting-network sorting-network-diagrams
Last synced: about 1 month ago
JSON representation
A Go utility for checking and rendering sorting networks
- Host: GitHub
- URL: https://github.com/brianpursley/sorting-network-go
- Owner: brianpursley
- License: mit
- Created: 2020-01-28T16:40:31.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-31T15:50:03.000Z (about 2 years ago)
- Last Synced: 2024-06-21T19:06:35.568Z (7 months ago)
- Topics: comparison-network, golang, sorting-algorithms, sorting-network, sorting-network-diagrams
- Language: Go
- Size: 35.2 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sorting-network-go
A Go utility for checking and rendering sorting networksAdapted from [this Python version](https://github.com/brianpursley/sorting-network)
## Usage
You specify a comparison network as a comma-separated list of comparators, where each comparator is formated like `X:Y` where `X` and `Y` are zero-based input indices. For example: `0:1,2:3,0:2,1:3,1:2`
### Load a 16-input comparison network from a file and check if it is a sorting network
```bash
$ go run cmd/sortingnetwork/sortingnetwork.go -input examples/16-input.cn -check
```
Output:
```
It is a sorting network!
```### Check a 4-input comparison network from stdin
```bash
$ echo 0:1,2:3,0:2,1:3,1:2 | go run cmd/sortingnetwork/sortingnetwork.go -check
```
Output:
```
It is a sorting network!
```### Check a 4-input comparison network from stdin (Not a sorting network)
```bash
$ echo 0:1,2:3,0:2,1:3 | go run cmd/sortingnetwork/sortingnetwork.go -check
```
Output:
```
It is not a sorting network.
```### Load a 4-input comparison network from a file and render it as an SVG
```bash
$ go run cmd/sortingnetwork/sortingnetwork.go -input examples/4-input.cn -svg > examples/4-input.svg
```### Load a 4-input comparison network from a file and render it as a PNG
You can use rsvg-convert to convert the output from SVG to some other format, like PNG. rsvg-convert can be installed by using `sudo apt-get install librsvg2-bin` on Ubuntu.
```bash
$ go run cmd/sortingnetwork/sortingnetwork.go -input examples/4-input.cn -svg | rsvg-convert > examples/4-input.png
```## Example sorting networks
### 4-Input
```text
0:1,2:3
0:2,1:3
1:2
```![4-Input Sorting Network](https://github.com/brianpursley/sorting-network-go/blob/master/examples/4-input.png)
### 5-Input
```text
0:1,3:4
2:4
2:3,1:4
0:3
0:2,1:3
1:2
```![5-Input Sorting Network](https://github.com/brianpursley/sorting-network-go/blob/master/examples/5-input.png)
### 16-Input
```text
0:1,2:3,4:5,6:7,8:9,10:11,12:13,14:15
0:2,1:3,4:6,5:7,8:10,9:11,12:14,13:15
0:4,1:5,2:6,3:7,8:12,9:13,10:14,11:15
0:8,1:9,2:10,3:11,4:12,5:13,6:14,7:15
5:10,6:9,3:12,13:14,7:11,1:2,4:8
1:4,7:13,2:8,11:14
2:4,5:6,9:10,11:13,3:8,7:12
6:8,10:12,3:5,7:9
3:4,5:6,7:8,9:10,11:12
6:7,8:9
```![16-Input Sorting Network](https://github.com/brianpursley/sorting-network-go/blob/master/examples/16-input.png)