Created
September 25, 2019 19:36
-
-
Save vyamkovyi/ec38d330ae3af2dcf4288879c00cd170 to your computer and use it in GitHub Desktop.
A simple byte slice wrapper.
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 "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