GitHunt
NE

nes1983/radixsort

General purpose Radix sort in go.

radixsort

General purpose Radix sort in go.

General purpose means that you can sort anything, not just int arrays.

You're supposed to use it like this:

type cell struct {
	rowKey, colKey uint
}

func (s []cell) SortKey(pos, priority int) (key int, ok bool) {
	switch priority {
		case 0:
			return s[pos].rowKey, true
		case 1:
			return s[pos].colKey, true
		default:
			return 0, false
	}
}

func (s []cell) Len() { return len(s) }
func (s []cell) Swap(i, j int) { s[i, j] = s[j, i] }

var cells []cell
cells = ...

radix.Sort(cells)

This should outperform the standard sort package, and does in my benchmarks.
Alas, it isn't quite done.

Languages

Go100.0%

Contributors

Created May 25, 2013
Updated October 27, 2013
nes1983/radixsort | GitHunt