forked from parquet-go/parquet-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.go
More file actions
27 lines (21 loc) · 849 Bytes
/
Copy patharray.go
File metadata and controls
27 lines (21 loc) · 849 Bytes
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
package parquet
import (
"unsafe"
"github.com/parquet-go/parquet-go/sparse"
)
// makeArrayVlaue constructs a sparse.Array from a slice of Value,
// using the offset to locate the field within the Value struct that
// the sparse array is indexing.
func makeArrayValue(values []Value, offset uintptr) sparse.Array {
ptr := unsafe.Pointer(unsafe.SliceData(values))
return sparse.UnsafeArray(unsafe.Add(ptr, offset), len(values), unsafe.Sizeof(Value{}))
}
func makeArray(base unsafe.Pointer, length int, offset uintptr) sparse.Array {
return sparse.UnsafeArray(base, length, offset)
}
func makeArrayFromSlice[T any](s []T) sparse.Array {
return makeArray(unsafe.Pointer(unsafe.SliceData(s)), len(s), unsafe.Sizeof(*new(T)))
}
func makeArrayFromPointer[T any](v *T) sparse.Array {
return makeArray(unsafe.Pointer(v), 1, unsafe.Sizeof(*v))
}