github.com/tursom/GoCollections@v0.3.10/lang/Array.go (about) 1 package lang 2 3 import "unsafe" 4 5 type ( 6 Array[T any] []T 7 8 Int8Array Array[Int8] 9 Int16Array Array[Int16] 10 Int32Array Array[Int32] 11 Int64Array Array[Int64] 12 UInt8Array Array[UInt8] 13 UInt16Array Array[UInt16] 14 UInt32Array Array[UInt32] 15 UInt64Array Array[UInt64] 16 Float32Array Array[Float32] 17 Float64Array Array[Float64] 18 Complex64Array Array[Complex64] 19 Complex128Array Array[Complex128] 20 ) 21 22 func (a Array[T]) Array() []T { 23 return a 24 } 25 26 func FromRawInt8Array(arr []int8) Int8Array { 27 return *(*Int8Array)(unsafe.Pointer(&arr)) 28 } 29 30 func FromRawInt16Array(arr []int16) Int16Array { 31 return *(*Int16Array)(unsafe.Pointer(&arr)) 32 } 33 34 func FromRawInt32Array(arr []int32) Int32Array { 35 return *(*Int32Array)(unsafe.Pointer(&arr)) 36 } 37 38 func FromRawInt64Array(arr []int64) Int64Array { 39 return *(*Int64Array)(unsafe.Pointer(&arr)) 40 } 41 42 func FromRawUInt8Array(arr []uint8) UInt8Array { 43 return *(*UInt8Array)(unsafe.Pointer(&arr)) 44 } 45 46 func FromRawUInt16Array(arr []uint16) UInt16Array { 47 return *(*UInt16Array)(unsafe.Pointer(&arr)) 48 } 49 50 func FromRawUInt32Array(arr []uint32) UInt32Array { 51 return *(*UInt32Array)(unsafe.Pointer(&arr)) 52 } 53 54 func FromRawUInt64Array(arr []uint64) UInt64Array { 55 return *(*UInt64Array)(unsafe.Pointer(&arr)) 56 } 57 58 func FromRawFloat32Array(arr []float32) Float32Array { 59 return *(*Float32Array)(unsafe.Pointer(&arr)) 60 } 61 62 func FromRawFloat64Array(arr []float64) Float64Array { 63 return *(*Float64Array)(unsafe.Pointer(&arr)) 64 } 65 66 func FromRawComplex64Array(arr []complex64) Complex64Array { 67 return *(*Complex64Array)(unsafe.Pointer(&arr)) 68 } 69 70 func FromRawComplex128Array(arr []complex128) Complex128Array { 71 return *(*Complex128Array)(unsafe.Pointer(&arr)) 72 } 73 74 func (a UInt8Array) Bytes() []byte { 75 return a.Raw() 76 } 77 78 func (a Int8Array) Raw() []int8 { 79 return *(*[]int8)(unsafe.Pointer(&a)) 80 } 81 82 func (a Int16Array) Raw() []int16 { 83 return *(*[]int16)(unsafe.Pointer(&a)) 84 } 85 86 func (a Int32Array) Raw() []int32 { 87 return *(*[]int32)(unsafe.Pointer(&a)) 88 } 89 90 func (a Int64Array) Raw() []int64 { 91 return *(*[]int64)(unsafe.Pointer(&a)) 92 } 93 94 func (a UInt8Array) Raw() []uint8 { 95 return *(*[]uint8)(unsafe.Pointer(&a)) 96 } 97 98 func (a UInt16Array) Raw() []uint16 { 99 return *(*[]uint16)(unsafe.Pointer(&a)) 100 } 101 102 func (a UInt32Array) Raw() []uint32 { 103 return *(*[]uint32)(unsafe.Pointer(&a)) 104 } 105 106 func (a UInt64Array) Raw() []uint64 { 107 return *(*[]uint64)(unsafe.Pointer(&a)) 108 } 109 110 func (a Float32Array) Raw() []float32 { 111 return *(*[]float32)(unsafe.Pointer(&a)) 112 } 113 114 func (a Float64Array) Raw() []float64 { 115 return *(*[]float64)(unsafe.Pointer(&a)) 116 } 117 118 func (a Complex64Array) Raw() []complex64 { 119 return *(*[]complex64)(unsafe.Pointer(&a)) 120 } 121 122 func (a Complex128Array) Raw() []complex128 { 123 return *(*[]complex128)(unsafe.Pointer(&a)) 124 } 125 126 func (a Int8Array) BitLength() uint { 127 return uint(len(a) * 8) 128 } 129 130 func (a Int16Array) BitLength() uint { 131 return uint(len(a) * 16) 132 } 133 134 func (a Int32Array) BitLength() uint { 135 return uint(len(a) * 32) 136 } 137 138 func (a Int64Array) BitLength() uint { 139 return uint(len(a) * 64) 140 } 141 142 func (a UInt8Array) BitLength() uint { 143 return uint(len(a) * 8) 144 } 145 146 func (a UInt16Array) BitLength() uint { 147 return uint(len(a) * 16) 148 } 149 150 func (a UInt32Array) BitLength() uint { 151 return uint(len(a) * 32) 152 } 153 154 func (a UInt64Array) BitLength() uint { 155 return uint(len(a) * 64) 156 } 157 158 func (a Int8Array) GetBit(index uint) (ok bool) { 159 return GetBit(a[index/8], index%8) 160 } 161 162 func (a Int16Array) GetBit(index uint) (ok bool) { 163 return GetBit(a[index/16], index%16) 164 } 165 166 func (a Int32Array) GetBit(index uint) (ok bool) { 167 return GetBit(a[index/32], index%32) 168 } 169 170 func (a Int64Array) GetBit(index uint) (ok bool) { 171 return GetBit(a[index/64], index%64) 172 } 173 174 func (a UInt8Array) GetBit(index uint) (ok bool) { 175 return GetBit(a[index/8], index%8) 176 } 177 178 func (a UInt16Array) GetBit(index uint) (ok bool) { 179 return GetBit(a[index/16], index%16) 180 } 181 182 func (a UInt32Array) GetBit(index uint) (ok bool) { 183 return GetBit(a[index/32], index%32) 184 } 185 186 func (a UInt64Array) GetBit(index uint) (ok bool) { 187 return GetBit(a[index/64], index%64) 188 } 189 190 func (a Int8Array) SetBit(index uint, up bool) { 191 SetBit(&a[index/8], index%8, up) 192 } 193 194 func (a Int16Array) SetBit(index uint, up bool) { 195 SetBit(&a[index/16], index%16, up) 196 } 197 198 func (a Int32Array) SetBit(index uint, up bool) { 199 SetBit(&a[index/32], index%32, up) 200 } 201 202 func (a Int64Array) SetBit(index uint, up bool) { 203 SetBit(&a[index/64], index%64, up) 204 } 205 206 func (a UInt8Array) SetBit(index uint, up bool) { 207 SetBit(&a[index/8], index%8, up) 208 } 209 210 func (a UInt16Array) SetBit(index uint, up bool) { 211 SetBit(&a[index/16], index%16, up) 212 } 213 214 func (a UInt32Array) SetBit(index uint, up bool) { 215 SetBit(&a[index/32], index%32, up) 216 } 217 218 func (a UInt64Array) SetBit(index uint, up bool) { 219 SetBit(&a[index/64], index%64, up) 220 } 221 222 func (a Int8Array) SwapBit(index uint, up bool) (old bool) { 223 return SwapBit(&a[index/8], index%8, up) 224 } 225 226 func (a Int16Array) SwapBit(index uint, up bool) (old bool) { 227 return SwapBit(&a[index/16], index%16, up) 228 } 229 230 func (a Int32Array) SwapBit(index uint, up bool) (old bool) { 231 return SwapBit(&a[index/32], index%32, up) 232 } 233 234 func (a Int64Array) SwapBit(index uint, up bool) (old bool) { 235 return SwapBit(&a[index/64], index%64, up) 236 } 237 238 func (a UInt8Array) SwapBit(index uint, up bool) (old bool) { 239 return SwapBit(&a[index/8], index%8, up) 240 } 241 242 func (a UInt16Array) SwapBit(index uint, up bool) (old bool) { 243 return SwapBit(&a[index/16], index%16, up) 244 } 245 246 func (a UInt32Array) SwapBit(index uint, up bool) (old bool) { 247 return SwapBit(&a[index/32], index%32, up) 248 } 249 250 func (a UInt64Array) SwapBit(index uint, up bool) (old bool) { 251 return SwapBit(&a[index/64], index%64, up) 252 }