Skip to content

Instantly share code, notes, and snippets.

@vyamkovyi
Created September 25, 2019 19:36
Show Gist options
  • Save vyamkovyi/ec38d330ae3af2dcf4288879c00cd170 to your computer and use it in GitHub Desktop.
Save vyamkovyi/ec38d330ae3af2dcf4288879c00cd170 to your computer and use it in GitHub Desktop.
A simple byte slice wrapper.
package main
import "sort"
// ByteSlice attaches the methods of sort.Interface to []byte, sorting in
// increasing order.
type ByteSlice []byte
func (s ByteSlice) Len() int { return len(s) }
func (s ByteSlice) Less(i, j int) bool { return s[i] < s[j] }
func (s ByteSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
// Sort is a convenience method.
func (s ByteSlice) Sort() {
sort.Sort(s)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment