2021-07-18 12:55:37 +00:00
|
|
|
/*
|
|
|
|
Package slice contains byte slice helpers.
|
|
|
|
*/
|
|
|
|
package slice
|
|
|
|
|
|
|
|
// CopyReverse returns a new byte slice containing reversed version of the
|
|
|
|
// original.
|
|
|
|
func CopyReverse(b []byte) []byte {
|
|
|
|
dest := make([]byte, len(b))
|
2021-07-18 13:08:23 +00:00
|
|
|
reverse(dest, b)
|
2021-07-18 12:55:37 +00:00
|
|
|
return dest
|
|
|
|
}
|
2021-07-18 13:08:23 +00:00
|
|
|
|
|
|
|
// Reverse does in-place reversing of byte slice.
|
|
|
|
func Reverse(b []byte) {
|
|
|
|
reverse(b, b)
|
|
|
|
}
|
|
|
|
|
|
|
|
func reverse(dst []byte, src []byte) {
|
|
|
|
for i, j := 0, len(src)-1; i <= j; i, j = i+1, j-1 {
|
|
|
|
dst[i], dst[j] = src[j], src[i]
|
|
|
|
}
|
|
|
|
}
|