Documentation
¶
Overview ¶
Package sparse contains abstractions to help work on arrays of values in sparse memory locations.
Conversion between array types is supported when converting integers to a lower size (e.g. int32 to int16, or uint64 to uint8), or converting from signed integers to unsigned. Float types can also be converted to unsigned integers of the same size, in which case the conversion is similar to using the standard library's math.Float32bits and math.Float64bits functions.
All array types can be converted to a generic Array type that can be used to erase type information and bypass type conversion rules. This conversion is similar to using Go's unsafe package to bypass Go's type system and should usually be avoided and a sign that the application is attempting to break type safety boundaries.
The package provides Gather* functions which retrieve values from sparse arrays into contiguous memory buffers. On platforms that support it, these operations are implemented using SIMD gather instructions (e.g. VPGATHER on Intel CPUs).
Index ¶
- func GatherBits(dst []byte, src Uint8Array) int
- func GatherFloat32(dst []float32, src Float32Array) int
- func GatherFloat64(dst []float64, src Float64Array) int
- func GatherInt32(dst []int32, src Int32Array) int
- func GatherInt64(dst []int64, src Int64Array) int
- func GatherString(dst []string, src StringArray) int
- func GatherUint128(dst [][16]byte, src Uint128Array) int
- func GatherUint32(dst []uint32, src Uint32Array) int
- func GatherUint64(dst []uint64, src Uint64Array) int
- type Array
- func (a Array) BoolArray() BoolArray
- func (a Array) Float32Array() Float32Array
- func (a Array) Float64Array() Float64Array
- func (a Array) Index(i int) unsafe.Pointer
- func (a Array) Int16Array() Int16Array
- func (a Array) Int32Array() Int32Array
- func (a Array) Int64Array() Int64Array
- func (a Array) Int8Array() Int8Array
- func (a Array) Len() int
- func (a Array) Offset(off uintptr) Array
- func (a Array) Slice(i, j int) Array
- func (a Array) StringArray() StringArray
- func (a Array) TimeArray() TimeArray
- func (a Array) Uint128Array() Uint128Array
- func (a Array) Uint16Array() Uint16Array
- func (a Array) Uint32Array() Uint32Array
- func (a Array) Uint64Array() Uint64Array
- func (a Array) Uint8Array() Uint8Array
- type BoolArray
- type Float32Array
- type Float64Array
- type Int16Array
- type Int32Array
- func (a Int32Array) Index(i int) int32
- func (a Int32Array) Int16Array() Int16Array
- func (a Int32Array) Int8Array() Int8Array
- func (a Int32Array) Len() int
- func (a Int32Array) Slice(i, j int) Int32Array
- func (a Int32Array) Uint16Array() Uint16Array
- func (a Int32Array) Uint32Array() Uint32Array
- func (a Int32Array) Uint8Array() Uint8Array
- func (a Int32Array) UnsafeArray() Array
- type Int64Array
- func (a Int64Array) Index(i int) int64
- func (a Int64Array) Int16Array() Int16Array
- func (a Int64Array) Int32Array() Int32Array
- func (a Int64Array) Int8Array() Int8Array
- func (a Int64Array) Len() int
- func (a Int64Array) Slice(i, j int) Int64Array
- func (a Int64Array) Uint16Array() Uint16Array
- func (a Int64Array) Uint32Array() Uint32Array
- func (a Int64Array) Uint64Array() Uint64Array
- func (a Int64Array) Uint8Array() Uint8Array
- func (a Int64Array) UnsafeArray() Array
- type Int8Array
- type StringArray
- type TimeArray
- type Uint128Array
- func (a Uint128Array) Index(i int) [16]byte
- func (a Uint128Array) Len() int
- func (a Uint128Array) Slice(i, j int) Uint128Array
- func (a Uint128Array) Uint16Array() Uint16Array
- func (a Uint128Array) Uint32Array() Uint32Array
- func (a Uint128Array) Uint64Array() Uint64Array
- func (a Uint128Array) Uint8Array() Uint8Array
- func (a Uint128Array) UnsafeArray() Array
- type Uint16Array
- type Uint32Array
- type Uint64Array
- func (a Uint64Array) Index(i int) uint64
- func (a Uint64Array) Len() int
- func (a Uint64Array) Slice(i, j int) Uint64Array
- func (a Uint64Array) Uint16Array() Uint16Array
- func (a Uint64Array) Uint32Array() Uint32Array
- func (a Uint64Array) Uint8Array() Uint8Array
- func (a Uint64Array) UnsafeArray() Array
- type Uint8Array
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GatherBits ¶
func GatherBits(dst []byte, src Uint8Array) int
func GatherFloat32 ¶
func GatherFloat32(dst []float32, src Float32Array) int
func GatherFloat64 ¶
func GatherFloat64(dst []float64, src Float64Array) int
func GatherInt32 ¶
func GatherInt32(dst []int32, src Int32Array) int
func GatherInt64 ¶
func GatherInt64(dst []int64, src Int64Array) int
func GatherString ¶
func GatherString(dst []string, src StringArray) int
Example ¶
package main import ( "fmt" "strconv" "unsafe" "github.com/alxarno/parquet-go-athena-list-hack/sparse" ) func main() { buf := make([][2]string, 10) dst := make([]string, 10) src := sparse.UnsafeStringArray(unsafe.Pointer(&buf[0][1]), len(buf), unsafe.Sizeof(buf[0])) for i := range buf { buf[i][0] = "-" buf[i][1] = strconv.Itoa(i) } n := sparse.GatherString(dst, src) for i, v := range dst[:n] { fmt.Printf("points[%d].Y = %v\n", i, v) } }
Output: points[0].Y = 0 points[1].Y = 1 points[2].Y = 2 points[3].Y = 3 points[4].Y = 4 points[5].Y = 5 points[6].Y = 6 points[7].Y = 7 points[8].Y = 8 points[9].Y = 9
func GatherUint128 ¶
func GatherUint128(dst [][16]byte, src Uint128Array) int
Example ¶
package main import ( "encoding/binary" "fmt" "math" "unsafe" "github.com/alxarno/parquet-go-athena-list-hack/sparse" ) func main() { type point2D struct{ X, Y [16]byte } buf := make([]point2D, 10) dst := make([][16]byte, 10) src := sparse.UnsafeUint128Array(unsafe.Pointer(&buf[0].Y), len(buf), unsafe.Sizeof(buf[0])) for i := range buf { x := uint64(math.MaxUint64) y := uint64(2 * i) binary.LittleEndian.PutUint64(buf[i].X[:], x) binary.LittleEndian.PutUint64(buf[i].Y[:], y) } n := sparse.GatherUint128(dst, src) for i, v := range dst[:n] { fmt.Printf("points[%d].Y = %v\n", i, binary.LittleEndian.Uint64(v[:])) } }
Output: points[0].Y = 0 points[1].Y = 2 points[2].Y = 4 points[3].Y = 6 points[4].Y = 8 points[5].Y = 10 points[6].Y = 12 points[7].Y = 14 points[8].Y = 16 points[9].Y = 18
func GatherUint32 ¶
func GatherUint32(dst []uint32, src Uint32Array) int
Example ¶
package main import ( "fmt" "math" "unsafe" "github.com/alxarno/parquet-go-athena-list-hack/sparse" ) func main() { type point2D struct{ X, Y uint32 } buf := make([]point2D, 10) dst := make([]uint32, 10) src := sparse.UnsafeUint32Array(unsafe.Pointer(&buf[0].Y), len(buf), unsafe.Sizeof(buf[0])) for i := range buf { buf[i].X = math.MaxUint32 buf[i].Y = uint32(2 * i) } n := sparse.GatherUint32(dst, src) for i, v := range dst[:n] { fmt.Printf("points[%d].Y = %d\n", i, v) } }
Output: points[0].Y = 0 points[1].Y = 2 points[2].Y = 4 points[3].Y = 6 points[4].Y = 8 points[5].Y = 10 points[6].Y = 12 points[7].Y = 14 points[8].Y = 16 points[9].Y = 18
func GatherUint64 ¶
func GatherUint64(dst []uint64, src Uint64Array) int
Example ¶
package main import ( "fmt" "math" "unsafe" "github.com/alxarno/parquet-go-athena-list-hack/sparse" ) func main() { type point2D struct{ X, Y uint64 } buf := make([]point2D, 10) dst := make([]uint64, 10) src := sparse.UnsafeUint64Array(unsafe.Pointer(&buf[0].Y), len(buf), unsafe.Sizeof(buf[0])) for i := range buf { buf[i].X = math.MaxUint64 buf[i].Y = uint64(2 * i) } n := sparse.GatherUint64(dst, src) for i, v := range dst[:n] { fmt.Printf("points[%d].Y = %v\n", i, v) } }
Output: points[0].Y = 0 points[1].Y = 2 points[2].Y = 4 points[3].Y = 6 points[4].Y = 8 points[5].Y = 10 points[6].Y = 12 points[7].Y = 14 points[8].Y = 16 points[9].Y = 18
Types ¶
type Array ¶
type Array struct {
// contains filtered or unexported fields
}
func (Array) Float32Array ¶
func (a Array) Float32Array() Float32Array
func (Array) Float64Array ¶
func (a Array) Float64Array() Float64Array
func (Array) Int16Array ¶
func (a Array) Int16Array() Int16Array
func (Array) Int32Array ¶
func (a Array) Int32Array() Int32Array
func (Array) Int64Array ¶
func (a Array) Int64Array() Int64Array
func (Array) StringArray ¶
func (a Array) StringArray() StringArray
func (Array) Uint128Array ¶
func (a Array) Uint128Array() Uint128Array
func (Array) Uint16Array ¶
func (a Array) Uint16Array() Uint16Array
func (Array) Uint32Array ¶
func (a Array) Uint32Array() Uint32Array
func (Array) Uint64Array ¶
func (a Array) Uint64Array() Uint64Array
func (Array) Uint8Array ¶
func (a Array) Uint8Array() Uint8Array
type BoolArray ¶
type BoolArray struct {
// contains filtered or unexported fields
}
func MakeBoolArray ¶
func UnsafeBoolArray ¶
func (BoolArray) Uint8Array ¶
func (a BoolArray) Uint8Array() Uint8Array
func (BoolArray) UnsafeArray ¶
type Float32Array ¶
type Float32Array struct {
// contains filtered or unexported fields
}
func MakeFloat32Array ¶
func MakeFloat32Array(values []float32) Float32Array
func UnsafeFloat32Array ¶
func UnsafeFloat32Array(base unsafe.Pointer, length int, offset uintptr) Float32Array
func (Float32Array) Array ¶
func (a Float32Array) Array() Array
func (Float32Array) Index ¶
func (a Float32Array) Index(i int) float32
func (Float32Array) Len ¶
func (a Float32Array) Len() int
func (Float32Array) Slice ¶
func (a Float32Array) Slice(i, j int) Float32Array
func (Float32Array) Uint32Array ¶
func (a Float32Array) Uint32Array() Uint32Array
func (Float32Array) UnsafeArray ¶
func (a Float32Array) UnsafeArray() Array
type Float64Array ¶
type Float64Array struct {
// contains filtered or unexported fields
}
func MakeFloat64Array ¶
func MakeFloat64Array(values []float64) Float64Array
func UnsafeFloat64Array ¶
func UnsafeFloat64Array(base unsafe.Pointer, length int, offset uintptr) Float64Array
func (Float64Array) Index ¶
func (a Float64Array) Index(i int) float64
func (Float64Array) Len ¶
func (a Float64Array) Len() int
func (Float64Array) Slice ¶
func (a Float64Array) Slice(i, j int) Float64Array
func (Float64Array) Uint64Array ¶
func (a Float64Array) Uint64Array() Uint64Array
func (Float64Array) UnsafeArray ¶
func (a Float64Array) UnsafeArray() Array
type Int16Array ¶
type Int16Array struct {
// contains filtered or unexported fields
}
func MakeInt16Array ¶
func MakeInt16Array(values []int16) Int16Array
func UnsafeInt16Array ¶
func UnsafeInt16Array(base unsafe.Pointer, length int, offset uintptr) Int16Array
func (Int16Array) Index ¶
func (a Int16Array) Index(i int) int16
func (Int16Array) Int8Array ¶
func (a Int16Array) Int8Array() Int8Array
func (Int16Array) Len ¶
func (a Int16Array) Len() int
func (Int16Array) Slice ¶
func (a Int16Array) Slice(i, j int) Int16Array
func (Int16Array) Uint16Array ¶
func (a Int16Array) Uint16Array() Uint16Array
func (Int16Array) Uint8Array ¶
func (a Int16Array) Uint8Array() Uint8Array
func (Int16Array) UnsafeArray ¶
func (a Int16Array) UnsafeArray() Array
type Int32Array ¶
type Int32Array struct {
// contains filtered or unexported fields
}
func MakeInt32Array ¶
func MakeInt32Array(values []int32) Int32Array
func UnsafeInt32Array ¶
func UnsafeInt32Array(base unsafe.Pointer, length int, offset uintptr) Int32Array
func (Int32Array) Index ¶
func (a Int32Array) Index(i int) int32
func (Int32Array) Int16Array ¶
func (a Int32Array) Int16Array() Int16Array
func (Int32Array) Int8Array ¶
func (a Int32Array) Int8Array() Int8Array
func (Int32Array) Len ¶
func (a Int32Array) Len() int
func (Int32Array) Slice ¶
func (a Int32Array) Slice(i, j int) Int32Array
func (Int32Array) Uint16Array ¶
func (a Int32Array) Uint16Array() Uint16Array
func (Int32Array) Uint32Array ¶
func (a Int32Array) Uint32Array() Uint32Array
func (Int32Array) Uint8Array ¶
func (a Int32Array) Uint8Array() Uint8Array
func (Int32Array) UnsafeArray ¶
func (a Int32Array) UnsafeArray() Array
type Int64Array ¶
type Int64Array struct {
// contains filtered or unexported fields
}
func MakeInt64Array ¶
func MakeInt64Array(values []int64) Int64Array
func UnsafeInt64Array ¶
func UnsafeInt64Array(base unsafe.Pointer, length int, offset uintptr) Int64Array
func (Int64Array) Index ¶
func (a Int64Array) Index(i int) int64
func (Int64Array) Int16Array ¶
func (a Int64Array) Int16Array() Int16Array
func (Int64Array) Int32Array ¶
func (a Int64Array) Int32Array() Int32Array
func (Int64Array) Int8Array ¶
func (a Int64Array) Int8Array() Int8Array
func (Int64Array) Len ¶
func (a Int64Array) Len() int
func (Int64Array) Slice ¶
func (a Int64Array) Slice(i, j int) Int64Array
func (Int64Array) Uint16Array ¶
func (a Int64Array) Uint16Array() Uint16Array
func (Int64Array) Uint32Array ¶
func (a Int64Array) Uint32Array() Uint32Array
func (Int64Array) Uint64Array ¶
func (a Int64Array) Uint64Array() Uint64Array
func (Int64Array) Uint8Array ¶
func (a Int64Array) Uint8Array() Uint8Array
func (Int64Array) UnsafeArray ¶
func (a Int64Array) UnsafeArray() Array
type Int8Array ¶
type Int8Array struct {
// contains filtered or unexported fields
}
func MakeInt8Array ¶
func UnsafeInt8Array ¶
func (Int8Array) Uint8Array ¶
func (a Int8Array) Uint8Array() Uint8Array
func (Int8Array) UnsafeArray ¶
type StringArray ¶
type StringArray struct {
// contains filtered or unexported fields
}
func MakeStringArray ¶
func MakeStringArray(values []string) StringArray
func UnsafeStringArray ¶
func UnsafeStringArray(base unsafe.Pointer, length int, offset uintptr) StringArray
func (StringArray) Index ¶
func (a StringArray) Index(i int) string
func (StringArray) Len ¶
func (a StringArray) Len() int
func (StringArray) Slice ¶
func (a StringArray) Slice(i, j int) StringArray
func (StringArray) UnsafeArray ¶
func (a StringArray) UnsafeArray() Array
type TimeArray ¶
type TimeArray struct {
// contains filtered or unexported fields
}
func MakeTimeArray ¶
func UnsafeTimeArray ¶
func (TimeArray) UnsafeArray ¶
type Uint128Array ¶
type Uint128Array struct {
// contains filtered or unexported fields
}
func MakeUint128Array ¶
func MakeUint128Array(values [][16]byte) Uint128Array
func UnsafeUint128Array ¶
func UnsafeUint128Array(base unsafe.Pointer, length int, offset uintptr) Uint128Array
func (Uint128Array) Index ¶
func (a Uint128Array) Index(i int) [16]byte
func (Uint128Array) Len ¶
func (a Uint128Array) Len() int
func (Uint128Array) Slice ¶
func (a Uint128Array) Slice(i, j int) Uint128Array
func (Uint128Array) Uint16Array ¶
func (a Uint128Array) Uint16Array() Uint16Array
func (Uint128Array) Uint32Array ¶
func (a Uint128Array) Uint32Array() Uint32Array
func (Uint128Array) Uint64Array ¶
func (a Uint128Array) Uint64Array() Uint64Array
func (Uint128Array) Uint8Array ¶
func (a Uint128Array) Uint8Array() Uint8Array
func (Uint128Array) UnsafeArray ¶
func (a Uint128Array) UnsafeArray() Array
type Uint16Array ¶
type Uint16Array struct {
// contains filtered or unexported fields
}
func MakeUint16Array ¶
func MakeUint16Array(values []uint16) Uint16Array
func UnsafeUint16Array ¶
func UnsafeUint16Array(base unsafe.Pointer, length int, offset uintptr) Uint16Array
func (Uint16Array) Index ¶
func (a Uint16Array) Index(i int) uint16
func (Uint16Array) Len ¶
func (a Uint16Array) Len() int
func (Uint16Array) Slice ¶
func (a Uint16Array) Slice(i, j int) Uint16Array
func (Uint16Array) Uint8Array ¶
func (a Uint16Array) Uint8Array() Uint8Array
func (Uint16Array) UnsafeArray ¶
func (a Uint16Array) UnsafeArray() Array
type Uint32Array ¶
type Uint32Array struct {
// contains filtered or unexported fields
}
func MakeUint32Array ¶
func MakeUint32Array(values []uint32) Uint32Array
func UnsafeUint32Array ¶
func UnsafeUint32Array(base unsafe.Pointer, length int, offset uintptr) Uint32Array
func (Uint32Array) Index ¶
func (a Uint32Array) Index(i int) uint32
func (Uint32Array) Len ¶
func (a Uint32Array) Len() int
func (Uint32Array) Slice ¶
func (a Uint32Array) Slice(i, j int) Uint32Array
func (Uint32Array) Uint16Array ¶
func (a Uint32Array) Uint16Array() Uint16Array
func (Uint32Array) Uint8Array ¶
func (a Uint32Array) Uint8Array() Uint8Array
func (Uint32Array) UnsafeArray ¶
func (a Uint32Array) UnsafeArray() Array
type Uint64Array ¶
type Uint64Array struct {
// contains filtered or unexported fields
}
func MakeUint64Array ¶
func MakeUint64Array(values []uint64) Uint64Array
func UnsafeUint64Array ¶
func UnsafeUint64Array(base unsafe.Pointer, length int, offset uintptr) Uint64Array
func (Uint64Array) Index ¶
func (a Uint64Array) Index(i int) uint64
func (Uint64Array) Len ¶
func (a Uint64Array) Len() int
func (Uint64Array) Slice ¶
func (a Uint64Array) Slice(i, j int) Uint64Array
func (Uint64Array) Uint16Array ¶
func (a Uint64Array) Uint16Array() Uint16Array
func (Uint64Array) Uint32Array ¶
func (a Uint64Array) Uint32Array() Uint32Array
func (Uint64Array) Uint8Array ¶
func (a Uint64Array) Uint8Array() Uint8Array
func (Uint64Array) UnsafeArray ¶
func (a Uint64Array) UnsafeArray() Array
type Uint8Array ¶
type Uint8Array struct {
// contains filtered or unexported fields
}
func MakeUint8Array ¶
func MakeUint8Array(values []uint8) Uint8Array
func UnsafeUint8Array ¶
func UnsafeUint8Array(base unsafe.Pointer, length int, offset uintptr) Uint8Array
func (Uint8Array) Index ¶
func (a Uint8Array) Index(i int) uint8
func (Uint8Array) Len ¶
func (a Uint8Array) Len() int
func (Uint8Array) Slice ¶
func (a Uint8Array) Slice(i, j int) Uint8Array
func (Uint8Array) UnsafeArray ¶
func (a Uint8Array) UnsafeArray() Array