Created
April 27, 2012 16:35
-
-
Save angeldm/2510624 to your computer and use it in GitHub Desktop.
Sort Byte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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