Documentation
¶
Overview ¶
Package Packed contains specific Array types that are more efficient and convenient to work with.
Index ¶
- func BinarySearch[T ~byte | ~float32 | ~float64 | ~int32 | ~int64](array Array[T], value T, before bool) int
- func Sort[T ~byte | ~float32 | ~float64 | ~int32 | ~int64](array Array[T])
- type Array
- func (array *Array[T]) Append(value T)
- func (array *Array[T]) AppendArray(other Array[T])
- func (array Array[T]) Bytes() Bytes
- func (array Array[T]) Clear()
- func (array Array[T]) Count(value T) int
- func (array Array[T]) Duplicate() Array[T]
- func (array Array[T]) Fill(value T)
- func (array Array[T]) Find(value T) int
- func (array Array[T]) FindLast(value T) int
- func (array Array[T]) Has(value T) bool
- func (array Array[T]) Index(idx int) T
- func (array *Array[T]) Insert(idx int, value T)
- func (array Array[T]) IsEmpty() bool
- func (array Array[T]) Iter() iter.Seq2[int, T]
- func (array Array[T]) Len() int
- func (array Array[T]) RemoveAt(idx int)
- func (array *Array[T]) Resize(size int)
- func (array Array[T]) Reverse()
- func (array *Array[T]) SetIndex(idx int, value T)
- func (array Array[T]) Slice(begin, end int) Array[T]
- func (array Array[T]) Values() iter.Seq[T]
- type Bytes
- func (array *Bytes) Append(value byte)
- func (array *Bytes) AppendArray(other Bytes)
- func (array Bytes) BinarySearch(value byte, before bool) int
- func (array Bytes) Bytes() []byte
- func (array Bytes) Clear()
- func (array Bytes) Compress(mode CompressionMode) Bytes
- func (array Bytes) Count(value byte) int
- func (array Bytes) Decode(offset uintptr) any
- func (array Bytes) DecodeFloat32(offset uintptr) float32
- func (array Bytes) DecodeFloat64(offset uintptr) float64
- func (array Bytes) DecodeInt16(offset uintptr) int16
- func (array Bytes) DecodeInt32(offset uintptr) int32
- func (array Bytes) DecodeInt64(offset uintptr) int64
- func (array Bytes) DecodeInt8(offset uintptr) int8
- func (array Bytes) DecodeSize(offset uintptr) uintptr
- func (array Bytes) DecodeUint16(offset uintptr) uint16
- func (array Bytes) DecodeUint32(offset uintptr) uint32
- func (array Bytes) DecodeUint64(offset uintptr) uint64
- func (array Bytes) DecodeUint8(offset uintptr) uint8
- func (array Bytes) DecompressSize(buffer_size int, mode CompressionMode) Bytes
- func (array Bytes) DecompressUpto(max_output_size int, mode CompressionMode) Bytes
- func (array Bytes) Duplicate() Bytes
- func (array Bytes) Encode(offset uintptr, value any)
- func (array Bytes) EncodeFloat32(offset uintptr, value float32)
- func (array Bytes) EncodeFloat64(offset uintptr, value float64)
- func (array Bytes) EncodeInt16(offset uintptr, value int16)
- func (array Bytes) EncodeInt32(offset uintptr, value int32)
- func (array Bytes) EncodeInt64(offset uintptr, value int64)
- func (array Bytes) EncodeInt8(offset uintptr, value int8)
- func (array Bytes) EncodeUint16(offset uintptr, value uint16)
- func (array Bytes) EncodeUint32(offset uintptr, value uint32)
- func (array Bytes) EncodeUint64(offset uintptr, value uint64)
- func (array Bytes) EncodeUint8(offset uintptr, value uint8)
- func (array Bytes) Fill(value byte)
- func (array Bytes) Find(value byte) int
- func (array Bytes) FindLast(value byte) int
- func (array Bytes) Has(value byte) bool
- func (array Bytes) HasVariantAt(offset int) bool
- func (array Bytes) Index(idx int) byte
- func (array *Bytes) Insert(idx int, value byte)
- func (array Bytes) IsEmpty() bool
- func (array Bytes) Iter() iter.Seq2[int, byte]
- func (array Bytes) Len() int
- func (array Bytes) RemoveAt(idx int)
- func (array *Bytes) Resize(size int)
- func (array Bytes) Reverse()
- func (array *Bytes) SetIndex(idx int, value byte)
- func (array Bytes) Slice(begin, end int) Bytes
- func (array Bytes) Sort()
- func (array Bytes) ToFloat32Array() Array[float32]
- func (array Bytes) ToFloat64Array() Array[float64]
- func (array Bytes) ToHex() string
- func (array Bytes) ToInt32Array() Array[int32]
- func (array Bytes) ToInt64Array() Array[int64]
- type CompressionMode
- type Strings
- func (array *Strings) Append(value String.Readable)
- func (array *Strings) AppendArray(other Strings)
- func (array Strings) BinarySearch(value String.Readable, before bool) int
- func (array Strings) Bytes() Bytes
- func (array Strings) Clear()
- func (array Strings) Count(value String.Readable) int
- func (array Strings) Duplicate() Strings
- func (array Strings) Fill(value String.Readable)
- func (array Strings) Find(value String.Readable) int
- func (array Strings) FindLast(value String.Readable) int
- func (array Strings) Has(value String.Readable) bool
- func (array Strings) Index(idx int) String.Readable
- func (array *Strings) Insert(idx int, value String.Readable)
- func (array Strings) IsEmpty() bool
- func (array Strings) Iter() iter.Seq2[int, String.Readable]
- func (array Strings) Len() int
- func (array Strings) RemoveAt(idx int)
- func (array *Strings) Resize(size int)
- func (array Strings) Reverse()
- func (array *Strings) SetIndex(idx int, value String.Readable)
- func (array Strings) Slice(begin, end int) Strings
- func (array Strings) Sort()
- func (array Strings) Strings() []string
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BinarySearch ¶
func BinarySearch[T ~byte | ~float32 | ~float64 | ~int32 | ~int64](array Array[T], value T, before bool) int
BinarySearch returns the index of value in the sorted array. If it cannot be found, returns where value should be inserted to keep the array sorted. The algorithm used is binary search. The returned index comes before all existing elements equal to value in the array.
Note: Calling BinarySearch on an unsorted array will result in unexpected behavior. Use Sort before calling this method.
Types ¶
type Array ¶
type Array[T Type] GenericArray.Contains[T]
Array contains comparable elements of type T Similar to [Array.Contains[T]] but for a supported Type is more efficient and convienient to work with.
func (*Array[T]) Append ¶
func (array *Array[T]) Append(value T)
Append an element to the end of the array.
func (*Array[T]) AppendArray ¶
AppendArray appends all elements of another array to the end of this array.
func (Array[T]) Clear ¶
func (array Array[T]) Clear()
Clear clears the array. This is equivalent to using resize with a size of 0.
func (Array[T]) Fill ¶
func (array Array[T]) Fill(value T)
Fill assigns the given value to all elements in the array. This can typically be used together with resize to create an array with a given size and initialized elements.
func (Array[T]) Find ¶
Find searches the array for a value and returns its index or -1 if not found.
func (Array[T]) FindLast ¶
FindLast searches the array in reverse order for a value and returns its index or -1 if not found.
func (*Array[T]) Insert ¶
Insert inserts a new element at a given position in the array. The position must be valid, or at the end of the array (idx == size()).
func (*Array[T]) Resize ¶
Resize sets the size of the array. If the array is grown, reserves elements at the end of the array. If the array is shrunk, truncates the array to the new size. Calling resize once and assigning the new values is faster than adding new elements one by one.
func (Array[T]) Reverse ¶
func (array Array[T]) Reverse()
Reverse reverses the order of the elements in the array.
type Bytes ¶
Bytes provides additional methods for working with arrays of bytes.
func (*Bytes) AppendArray ¶
AppendArray appends all elements of another array to the end of this array.
func (Bytes) BinarySearch ¶
BinarySearch returns the index of value in the sorted array. If it cannot be found, returns where value should be inserted to keep the array sorted. The algorithm used is binary search. The returned index comes before all existing elements equal to value in the array.
Note: Calling BinarySearch on an unsorted array will result in unexpected behavior. Use Sort before calling this method.
func (Bytes) Clear ¶
func (array Bytes) Clear()
Clear clears the array. bytehis is equivalent to using resize with a size of 0.
func (Bytes) Compress ¶
func (array Bytes) Compress(mode CompressionMode) Bytes
Compress returns a new PackedByteArray with the data compressed. Set the compression mode using one of CompressionMode's constants.
func (Bytes) Decode ¶
Decode a variant-encoded value from the bytes starting at offset. Returns null if a valid variant can't be decoded.
func (Bytes) DecodeFloat32 ¶
DecodeFloat32 decodes a 32-bit floating-point number from the bytes starting at offset. Fails if the byte count is insufficient. Returns 0.0 if a valid number can't be decoded.
func (Bytes) DecodeFloat64 ¶
DecodeFloat64 decodes a 64-bit floating-point number from the bytes starting at offset. Fails if the byte count is insufficient. Returns 0.0 if a valid number can't be decoded.
func (Bytes) DecodeInt16 ¶
DecodeInt16 decodes a 16-bit signed integer number from the bytes starting at offset. Fails if the byte count is insufficient. Returns 0 if a valid number can't be decoded.
func (Bytes) DecodeInt32 ¶
DecodeInt32 decodes a 32-bit signed integer number from the bytes starting at offset. Fails if the byte count is insufficient. Returns 0 if a valid number can't be decoded.
func (Bytes) DecodeInt64 ¶
DecodeInt64 decodes a 64-bit signed integer number from the bytes starting at offset. Fails if the byte count is insufficient. Returns 0 if a valid number can't be decoded.
func (Bytes) DecodeInt8 ¶
DecodeInt8 decodes a 8-bit signed integer number from the bytes starting at offset. Fails if the byte count is insufficient. Returns 0 if a valid number can't be decoded.
func (Bytes) DecodeSize ¶
Decodes a size of a Variant from the bytes starting at offset. Requires at least 4 bytes of data starting at the offset, otherwise fails.
func (Bytes) DecodeUint16 ¶
DecodeUint16 decodes a 16-bit unsigned integer number from the bytes starting at offset. Fails if the byte count is insufficient. Returns 0 if a valid number can't be decoded.
func (Bytes) DecodeUint32 ¶
DecodeUint32 decodes a 32-bit unsigned integer number from the bytes starting at offset. Fails if the byte count is insufficient. Returns 0 if a valid number can't be decoded.
func (Bytes) DecodeUint64 ¶
DecodeUint64 decodes a 64-bit unsigned integer number from the bytes starting at offset. Fails if the byte count is insufficient. Returns 0 if a valid number can't be decoded.
func (Bytes) DecodeUint8 ¶
DecodeUint8 decodes a 8-bit unsigned integer number from the bytes starting at offset. Fails if the byte count is insufficient. Returns 0 if a valid number can't be decoded.
func (Bytes) DecompressSize ¶
func (array Bytes) DecompressSize(buffer_size int, mode CompressionMode) Bytes
Decompress returns a new PackedByteArray with the data decompressed. Set buffer_size to the size of the uncompressed data. Set the compression mode using one of CompressionMode's constants.
func (Bytes) DecompressUpto ¶
func (array Bytes) DecompressUpto(max_output_size int, mode CompressionMode) Bytes
DecompressUpto returns a new PackedByteArray with the data decompressed. Set the compression mode using one of CompressionMode's constants. This method only accepts brotli, gzip, and deflate compression modes.
This method is potentially slower than decompress, as it may have to re-allocate its output buffer multiple times while decompressing, whereas decompress knows it's output buffer size from the beginning.
func (Bytes) Encode ¶
Encode a variant-encoded value at the index of offset bytes. Sufficient space must be allocated, depending on the encoded variant's size
func (Bytes) EncodeFloat32 ¶
EncodeFloat32 encodes a 32-bit floating-point number as bytes at the index of offset bytes. The array must have at least 4 bytes of allocated space, starting at the offset.
func (Bytes) EncodeFloat64 ¶
EncodeFloat64 encodes a 64-bit floating-point number as bytes at the index of offset bytes. The array must have at least 8 bytes of allocated space, starting at the offset.
func (Bytes) EncodeInt16 ¶
EncodeInt16 encodes a 16-bit signed integer number as bytes at the index of offset bytes. The array must have at least 2 bytes of allocated space, starting at the offset.
func (Bytes) EncodeInt32 ¶
EncodeInt32 encodes a 32-bit signed integer number as bytes at the index of offset bytes. The array must have at least 4 bytes of allocated space, starting at the offset.
func (Bytes) EncodeInt64 ¶
EncodeInt64 encodes a 64-bit signed integer number as bytes at the index of offset bytes. The array must have at least 8 bytes of allocated space, starting at the offset.
func (Bytes) EncodeInt8 ¶
EncodeInt8 encodes a 8-bit signed integer number as bytes at the index of offset bytes. The array must have at least 1 byte of allocated space, starting at the offset.
func (Bytes) EncodeUint16 ¶
EncodeUint16 encodes a 16-bit unsigned integer number as bytes at the index of offset bytes. The array must have at least 2 bytes of allocated space, starting at the offset.
func (Bytes) EncodeUint32 ¶
EncodeUint32 encodes a 32-bit unsigned integer number as bytes at the index of offset bytes. The array must have at least 4 bytes of allocated space, starting at the offset.
func (Bytes) EncodeUint64 ¶
EncodeUint64 encodes a 64-bit unsigned integer number as bytes at the index of offset bytes. The array must have at least 8 bytes of allocated space, starting at the offset.
func (Bytes) EncodeUint8 ¶
EncodeUint8 encodes a 8-bit unsigned integer number as bytes at the index of offset bytes. The array must have at least 1 byte of allocated space, starting at the offset.
func (Bytes) Fill ¶
Fill assigns the given value to all elements in the array. bytehis can typically be used together with resize to create an array with a given size and initialized elements.
func (Bytes) FindLast ¶
FindLast searches the array in reverse order for a value and returns its index or -1 if not found.
func (Bytes) HasVariantAt ¶
HasVariantAt returns true if a valid Variant value can be decoded at the byte_offset. Returns false otherwise
func (*Bytes) Insert ¶
Insert inserts a new element at a given position in the array. bytehe position must be valid, or at the end of the array (idx == size()).
func (*Bytes) Resize ¶
Resize sets the size of the array. If the array is grown, reserves elements at the end of the array. If the array is shrunk, truncates the array to the new size. Calling resize once and assigning the new values is faster than adding new elements one by one.
func (Bytes) Reverse ¶
func (array Bytes) Reverse()
Reverse reverses the order of the elements in the array.
func (Bytes) Slice ¶
Slice returns a slice of the array from the given begin index to the given end index.
func (Bytes) Sort ¶
func (array Bytes) Sort()
Sort sorts the array in ascending order. The final order is dependent on the "less than" (<) comparison between elements.
func (Bytes) ToFloat32Array ¶
ToFloat32Array returns a copy of the data converted to a PackedFloat32Array, where each block of 4 bytes has been converted to a 32-bit floating point number. The size of the input array must be a multiple of 4 (size of 32-bit float). The size of the new array will be byte_array.size() / 4. If the original data can't be converted to 32-bit floats, the resulting data is undefined.
func (Bytes) ToFloat64Array ¶
ToFloat64Array returns a copy of the data converted to a PackedFloat64Array, where each block of 8 bytes has been converted to a 64-bit floating point number. The size of the input array must be a multiple of 8 (size of 64-bit float). The size of the new array will be byte_array.size() / 8. If the original data can't be converted to 64-bit floats, the resulting data is undefined.
func (Bytes) ToInt32Array ¶
ToInt32Array returns a copy of the data converted to a PackedInt32Array, where each block of 4 bytes has been converted to a signed 32-bit integer.
The size of the input array must be a multiple of 4 (size of 32-bit integer). The size of the new array will be byte_array.size() / 4.
If the original data can't be converted to signed 32-bit integers, the resulting data is undefined.
func (Bytes) ToInt64Array ¶
ToInt64Array returns a copy of the data converted to a PackedInt64Array, where each block of 8 bytes has been converted to a signed 64-bit integer. The size of the input array must be a multiple of 8 (size of 64-bit integer). The size of the new array will be byte_array.size() / 8. If the original data can't be converted to signed 64-bit integers, the resulting data is undefined.
type CompressionMode ¶
type CompressionMode int
const ( CompressionFastLZ CompressionMode = iota CompressionDeflate CompressionZstandard // not implemented CompressionGzip CompressionBrotli // not implemented )
type Strings ¶
type Strings GenericArray.Contains[String.Readable]
Strings is a packed array of readable strings.
func MakeStrings ¶
MakeStrings creates a new array of strings with the given values.
func (*Strings) AppendArray ¶
AppendArray appends all elements of another array to the end of this array.
func (Strings) BinarySearch ¶
BinarySearch returns the index of value in the sorted array. If it cannot be found, returns where value should be inserted to keep the array sorted. The algorithm used is binary search. The returned index comes before all existing elements equal to value in the array.
Note: Calling BinarySearch on an unsorted array will result in unexpected behavior. Use Sort before calling this method.
func (Strings) Clear ¶
func (array Strings) Clear()
Clear clears the array. String.Readablehis is equivalent to using resize with a size of 0.
func (Strings) Fill ¶
Fill assigns the given value to all elements in the array. String.Readablehis can typically be used together with resize to create an array with a given size and initialized elements.
func (Strings) FindLast ¶
FindLast searches the array in reverse order for a value and returns its index or -1 if not found.
func (*Strings) Insert ¶
Insert inserts a new element at a given position in the array. String.Readablehe position must be valid, or at the end of the array (idx == size()).
func (*Strings) Resize ¶
Resize sets the size of the array. If the array is grown, reserves elements at the end of the array. If the array is shrunk, truncates the array to the new size. Calling resize once and assigning the new values is faster than adding new elements one by one.
func (Strings) Reverse ¶
func (array Strings) Reverse()
Reverse reverses the order of the elements in the array.
func (Strings) Slice ¶
Slice returns a slice of the array from the given begin index to the given end index.