https://github.com/jeffreysarnoff/sortingnetworks.jl
Sort 1..25 values with conditional swaps
https://github.com/jeffreysarnoff/sortingnetworks.jl
julia sorting
Last synced: about 1 year ago
JSON representation
Sort 1..25 values with conditional swaps
- Host: GitHub
- URL: https://github.com/jeffreysarnoff/sortingnetworks.jl
- Owner: JeffreySarnoff
- License: mit
- Created: 2017-02-14T17:54:36.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-08-06T07:41:17.000Z (almost 2 years ago)
- Last Synced: 2025-04-10T05:26:38.451Z (about 1 year ago)
- Topics: julia, sorting
- Language: Julia
- Homepage:
- Size: 137 KB
- Stars: 17
- Watchers: 1
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SortingNetworks.jl
Sort 1..25 values with conditional swaps. [](https://travis-ci.org/JeffreySarnoff/SortingNetworks.jl)
##### Copyright ©2017-2022 by Jeffrey Sarnoff.
------
Sorting networks that process 1,2,..25 values are given.
These sorting networks should minimize conditional swaps.
The first sixteen are known to minimize conditional swaps.
Values may be given with the args `swapsort(x1::T, .., xn::T)::NTuple{n,T}`
Values may be given using a tuple `swapsort(tup::NTuple{n,T})::NTuple{n,T}`
These sorts return a tuple of values sorted in ascending order.
#### Install
`Pkg.add("SortingNetworks")`
#### Use
```julia
using SortingNetworks
jumble = (5,3,1,4,2)
sorted = (1,2,3,4,5)
ascending = swapsort(5,3,1,4,2)
ascending == sorted
ascending == swapsort(jumble)
ascending == sorted
```
With v0.6-dev, timing sort([a,b,..]) relative to swapsort(a,b,...),
I got 15x for 4 Ints, 11x for 8 Ints, 5.75x for 16 Ints
##### acknowlegement
Jan Weidner provided **provably correct** code to test each implementation.