github.com/parquet-go/parquet-go@v0.20.0/array.go (about)

     1  package parquet
     2  
     3  import (
     4  	"unsafe"
     5  
     6  	"github.com/parquet-go/parquet-go/internal/unsafecast"
     7  	"github.com/parquet-go/parquet-go/sparse"
     8  )
     9  
    10  func makeArrayValue(values []Value, offset uintptr) sparse.Array {
    11  	ptr := *(*unsafe.Pointer)(unsafe.Pointer(&values))
    12  	return sparse.UnsafeArray(unsafe.Add(ptr, offset), len(values), unsafe.Sizeof(Value{}))
    13  }
    14  
    15  func makeArrayString(values []string) sparse.Array {
    16  	str := ""
    17  	ptr := *(*unsafe.Pointer)(unsafe.Pointer(&values))
    18  	return sparse.UnsafeArray(ptr, len(values), unsafe.Sizeof(str))
    19  }
    20  
    21  func makeArrayBE128(values []*[16]byte) sparse.Array {
    22  	ptr := *(*unsafe.Pointer)(unsafe.Pointer(&values))
    23  	return sparse.UnsafeArray(ptr, len(values), unsafe.Sizeof((*[16]byte)(nil)))
    24  }
    25  
    26  func makeArray(base unsafe.Pointer, length int, offset uintptr) sparse.Array {
    27  	return sparse.UnsafeArray(base, length, offset)
    28  }
    29  
    30  func makeArrayOf[T any](s []T) sparse.Array {
    31  	var model T
    32  	return makeArray(unsafecast.PointerOf(s), len(s), unsafe.Sizeof(model))
    33  }
    34  
    35  func makeSlice[T any](a sparse.Array) []T {
    36  	return slice[T](a.Index(0), a.Len())
    37  }
    38  
    39  func slice[T any](p unsafe.Pointer, n int) []T {
    40  	return unsafe.Slice((*T)(p), n)
    41  }
    42  
    43  type sliceHeader struct {
    44  	base unsafe.Pointer
    45  	len  int
    46  	cap  int
    47  }