mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-28 23:27:36 +00:00
19717dd9a8
It's a bit more convenient to use.
30 lines
616 B
Go
30 lines
616 B
Go
/*
|
|
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))
|
|
reverse(dest, b)
|
|
return dest
|
|
}
|
|
|
|
// 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]
|
|
}
|
|
}
|
|
|
|
// Copy copies the byte slice into new slice (make/copy).
|
|
func Copy(b []byte) []byte {
|
|
d := make([]byte, len(b))
|
|
copy(d, b)
|
|
return d
|
|
}
|