Packed

package
v0.0.0-...-ae8aae0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package Packed contains specific Array types that are more efficient and convenient to work with.

Package Packed provides functions for working with packed arrays.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 New

func New[T Type](values ...T) Array[T]

New creates a new array with the given values.

func (*Array[T]) Append

func (array *Array[T]) Append(value T)

Append an element to the end of the array.

func (*Array[T]) AppendArray

func (array *Array[T]) AppendArray(other Array[T])

AppendArray appends all elements of another array to the end of this array.

func (Array[T]) Bytes

func (array Array[T]) Bytes() Bytes

Bytes returns the underlying data in the array as Bytes.

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]) Count

func (array Array[T]) Count(value T) int

Count returns the number of times an element is in the array.

func (Array[T]) Duplicate

func (array Array[T]) Duplicate() Array[T]

Duplicate creates a copy of the array, and returns it.

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

func (array Array[T]) Find(value T) int

Find searches the array for a value and returns its index or -1 if not found.

func (Array[T]) FindLast

func (array Array[T]) FindLast(value T) int

FindLast searches the array in reverse order for a value and returns its index or -1 if not found.

func (Array[T]) Has

func (array Array[T]) Has(value T) bool

Has returns true if the array contains the given value.

func (Array[T]) Index

func (array Array[T]) Index(idx int) T

Index returns the element at the given index.

func (*Array[T]) Insert

func (array *Array[T]) Insert(idx int, value T)

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]) IsEmpty

func (array Array[T]) IsEmpty() bool

IsEmpty Returns true if the array is empty.

func (Array[T]) Iter

func (array Array[T]) Iter() iter.Seq2[int, T]

Iter returns an iterator for the array.

func (Array[T]) Len

func (array Array[T]) Len() int

Len returns the number of elements in the array.

func (Array[T]) RemoveAt

func (array Array[T]) RemoveAt(idx int)

RemoveAt removes an element from the array by index.

func (*Array[T]) Resize

func (array *Array[T]) Resize(size int)

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.

func (*Array[T]) SetIndex

func (array *Array[T]) SetIndex(idx int, value T)

SetIndex sets the value of the element at the given index.

func (Array[T]) Slice

func (array Array[T]) Slice(begin, end int) Array[T]

Slice returns a slice of the array from the given begin index to the given end index.

func (Array[T]) Values

func (array Array[T]) Values() iter.Seq[T]

Values returns an iterator on the values of the array.

type Bytes

type Bytes Array[byte]

Bytes provides additional methods for working with arrays of bytes.

func (*Bytes) Append

func (array *Bytes) Append(value byte)

Append an element to the end of the array.

func (*Bytes) AppendArray

func (array *Bytes) AppendArray(other Bytes)

AppendArray appends all elements of another array to the end of this array.

func (Bytes) Bytes

func (array Bytes) Bytes() []byte

Bytes returns the underlying data in the array as a slice of bytes.

func (Bytes) Clear

func (array Bytes) Clear()

Clear clears the array. bytehis is equivalent to using resize with a size of 0.

func (Bytes) Count

func (array Bytes) Count(value byte) int

Count returns the number of times an element is in the array.

func (Bytes) Duplicate

func (array Bytes) Duplicate() Bytes

Duplicate creates a copy of the array, and returns it.

func (Bytes) Fill

func (array Bytes) Fill(value byte)

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) Find

func (array Bytes) Find(value byte) int

Find searches the array for a value and returns its index or -1 if not found.

func (Bytes) FindLast

func (array Bytes) FindLast(value byte) int

FindLast searches the array in reverse order for a value and returns its index or -1 if not found.

func (Bytes) Has

func (array Bytes) Has(value byte) bool

Has returns true if the array contains the given value.

func (Bytes) Index

func (array Bytes) Index(idx int) byte

Index returns the element at the given index.

func (*Bytes) Insert

func (array *Bytes) Insert(idx int, value byte)

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) IsEmpty

func (array Bytes) IsEmpty() bool

IsEmpty Returns true if the array is empty.

func (Bytes) Iter

func (array Bytes) Iter() iter.Seq2[int, byte]

Iter returns an iterator for the array.

func (Bytes) Len

func (array Bytes) Len() int

Len returns the number of elements in the array.

func (Bytes) RemoveAt

func (array Bytes) RemoveAt(idx int)

RemoveAt removes an element from the array by index.

func (*Bytes) Resize

func (array *Bytes) Resize(size int)

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) SetIndex

func (array *Bytes) SetIndex(idx int, value byte)

SetIndex sets the value of the element at the given index.

func (Bytes) Slice

func (array Bytes) Slice(begin, end int) Bytes

Slice returns a slice of the array from the given begin index to the given end index.

type Strings

Strings is a packed array of readable strings.

func MakeStrings

func MakeStrings(values ...string) Strings

MakeStrings creates a new array of strings with the given values.

func (*Strings) Append

func (array *Strings) Append(value String.Readable)

Append an element to the end of the array.

func (*Strings) AppendArray

func (array *Strings) AppendArray(other Strings)

AppendArray appends all elements of another array to the end of this array.

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) Count

func (array Strings) Count(value String.Readable) int

Count returns the number of times an element is in the array.

func (Strings) Duplicate

func (array Strings) Duplicate() Strings

Duplicate creates a copy of the array, and returns it.

func (Strings) Fill

func (array Strings) Fill(value String.Readable)

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) Find

func (array Strings) Find(value String.Readable) int

Find searches the array for a value and returns its index or -1 if not found.

func (Strings) FindLast

func (array Strings) FindLast(value String.Readable) int

FindLast searches the array in reverse order for a value and returns its index or -1 if not found.

func (Strings) Has

func (array Strings) Has(value String.Readable) bool

Has returns true if the array contains the given value.

func (Strings) Index

func (array Strings) Index(idx int) String.Readable

Index returns the element at the given index.

func (*Strings) Insert

func (array *Strings) Insert(idx int, value String.Readable)

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) IsEmpty

func (array Strings) IsEmpty() bool

IsEmpty Returns true if the array is empty.

func (Strings) Iter

func (array Strings) Iter() iter.Seq2[int, String.Readable]

Iter returns an iterator for the array.

func (Strings) Len

func (array Strings) Len() int

Len returns the number of elements in the array.

func (Strings) RemoveAt

func (array Strings) RemoveAt(idx int)

RemoveAt removes an element from the array by index.

func (*Strings) Resize

func (array *Strings) Resize(size int)

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) SetIndex

func (array *Strings) SetIndex(idx int, value String.Readable)

SetIndex sets the value of the element at the given index.

func (Strings) Slice

func (array Strings) Slice(begin, end int) Strings

Slice returns a slice of the array from the given begin index to the given end index.

func (Strings) Strings

func (array Strings) Strings() []string

Strings returns a slice of strings from the array.

type Type

type Type interface {
	~byte | ~Color.RGBA | ~float32 | ~float64 | ~int32 | ~int64 | ~Vector2.XY | ~Vector3.XYZ | ~Vector4.XYZW
}

Type supported by Array.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL