1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
package qsort
import "unsafe"
func unsafeBytesTo64(b []byte) []uint64 {
return *(*[]uint64)(unsafe.Pointer(cast(b, 8)))
}
func unsafeBytesTo128(b []byte) []uint128 {
return *(*[]uint128)(unsafe.Pointer(cast(b, 16)))
}
func unsafeBytesTo192(b []byte) []uint192 {
return *(*[]uint192)(unsafe.Pointer(cast(b, 24)))
}
func unsafeBytesTo256(b []byte) []uint256 {
return *(*[]uint256)(unsafe.Pointer(cast(b, 32)))
}
func cast(b []byte, size int) *sliceHeader {
return &sliceHeader{
Data: *(*unsafe.Pointer)(unsafe.Pointer(&b)),
Len: len(b) / size,
Cap: len(b) / size,
}
}
type sliceHeader struct {
Data unsafe.Pointer
Len int
Cap int
}
|