Skip to content

Instantly share code, notes, and snippets.

@angeldm
Created April 27, 2012 16:35
Show Gist options
  • Save angeldm/2510624 to your computer and use it in GitHub Desktop.
Save angeldm/2510624 to your computer and use it in GitHub Desktop.
Sort Byte
package main
import (
"fmt"
"sort"
)
type ByteSlice []byte
func (p ByteSlice) Len() int { return len(p) }
func (p ByteSlice) Less(i, j int) bool { return p[i] < p[j] }
func (p ByteSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
// Sort is a convenience method.
func main() {
b := []byte("hola")
bs := ByteSlice(b)
sort.Sort(bs)
fmt.Println(bs)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment