]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/go/arrow/type_traits_float16.go
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / go / arrow / type_traits_float16.go
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16
17 package arrow
18
19 import (
20 "reflect"
21 "unsafe"
22
23 "github.com/apache/arrow/go/v6/arrow/float16"
24 "github.com/apache/arrow/go/v6/arrow/endian"
25 )
26
27 // Float16 traits
28 var Float16Traits float16Traits
29
30 const (
31 // Float16SizeBytes specifies the number of bytes required to store a single float16 in memory
32 Float16SizeBytes = int(unsafe.Sizeof(uint16(0)))
33 )
34
35 type float16Traits struct{}
36
37 // BytesRequired returns the number of bytes required to store n elements in memory.
38 func (float16Traits) BytesRequired(n int) int { return Float16SizeBytes * n }
39
40 // PutValue
41 func (float16Traits) PutValue(b []byte, v float16.Num) {
42 endian.Native.PutUint16(b, uint16(v.Uint16()))
43 }
44
45 // CastFromBytes reinterprets the slice b to a slice of type uint16.
46 //
47 // NOTE: len(b) must be a multiple of Uint16SizeBytes.
48 func (float16Traits) CastFromBytes(b []byte) []float16.Num {
49 h := (*reflect.SliceHeader)(unsafe.Pointer(&b))
50
51 var res []float16.Num
52 s := (*reflect.SliceHeader)(unsafe.Pointer(&res))
53 s.Data = h.Data
54 s.Len = h.Len / Float16SizeBytes
55 s.Cap = h.Cap / Float16SizeBytes
56
57 return res
58 }
59
60 // CastToBytes reinterprets the slice b to a slice of bytes.
61 func (float16Traits) CastToBytes(b []float16.Num) []byte {
62 h := (*reflect.SliceHeader)(unsafe.Pointer(&b))
63
64 var res []byte
65 s := (*reflect.SliceHeader)(unsafe.Pointer(&res))
66 s.Data = h.Data
67 s.Len = h.Len * Float16SizeBytes
68 s.Cap = h.Cap * Float16SizeBytes
69
70 return res
71 }
72
73 // Copy copies src to dst.
74 func (float16Traits) Copy(dst, src []float16.Num) { copy(dst, src) }