Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A Go utility for checking and rendering sorting networks

License

NotificationsYou must be signed in to change notification settings

brianpursley/sorting-network-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Go utility for checking and rendering sorting networks

Adapted fromthis Python version

Usage

You specify a comparison network as a comma-separated list of comparators, where each comparator is formated likeX:Y whereX andY 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

$ 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

$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)

$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

$ 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 usingsudo apt-get install librsvg2-bin on Ubuntu.

$ go run cmd/sortingnetwork/sortingnetwork.go -input examples/4-input.cn -svg| rsvg-convert> examples/4-input.png

Example sorting networks

4-Input

0:1,2:30:2,1:31:2

4-Input Sorting Network

5-Input

0:1,3:42:42:3,1:40:30:2,1:31:2

5-Input Sorting Network

16-Input

0:1,2:3,4:5,6:7,8:9,10:11,12:13,14:150:2,1:3,4:6,5:7,8:10,9:11,12:14,13:150:4,1:5,2:6,3:7,8:12,9:13,10:14,11:150:8,1:9,2:10,3:11,4:12,5:13,6:14,7:155:10,6:9,3:12,13:14,7:11,1:2,4:81:4,7:13,2:8,11:142:4,5:6,9:10,11:13,3:8,7:126:8,10:12,3:5,7:93:4,5:6,7:8,9:10,11:126:7,8:9

16-Input Sorting Network

About

A Go utility for checking and rendering sorting networks

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp