array

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array[T any] struct {
	// contains filtered or unexported fields
}

Array is a collection that stores elements in a contiguous memory block. The zero value is ready to use. Do not copy a non-zero Array.

func FromSlice

func FromSlice[T any](slice []T) *Array[T]

FromSlice creates a new Array from the specified slice.

func New

func New[T any]() *Array[T]

New creates an empty Array.

func NewFromIterable added in v1.6.1

func NewFromIterable[T any](iterable iter.Iterable[T]) *Array[T]

NewFromIterable creates a new Array from the specified iter.Iterable.

func NewWithCapacity

func NewWithCapacity[T any](initialCapacity int) *Array[T]

NewWithCapacity creates an empty Array with the specified initial capacity.

func NewWithSize

func NewWithSize[T any](initialSize int) *Array[T]

NewWithSize creates an empty Array with the specified initial size.

func (*Array[T]) Append

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

Append appends the specified element to the end of the Array.

func (*Array[T]) AppendMany

func (arr *Array[T]) AppendMany(values ...T)

AppendMany appends the specified elements to the end of the Array.

func (*Array[T]) Capacity

func (arr *Array[T]) Capacity() int

Capacity returns the number of elements that the Array can hold without reallocating.

func (*Array[T]) Clear

func (arr *Array[T]) Clear()

Clear removes all elements from the Array.

func (*Array[T]) Clone

func (arr *Array[T]) Clone() cols.Collection[T]

Clone returns a copy of the Array.

func (*Array[T]) CollectionIterator

func (arr *Array[T]) CollectionIterator() cols.Iterator[T]

CollectionIterator returns an iterator over the elements in the Array.

func (*Array[T]) FindIndex

func (arr *Array[T]) FindIndex(predicate predication.Predicate[T]) (int, bool)

FindIndex returns the index of the first element that matches the specified predicate.

func (*Array[T]) FindRef

func (arr *Array[T]) FindRef(predicate predication.Predicate[T]) (*T, bool)

FindRef returns a reference to the first element that matches the specified predicate.

func (*Array[T]) Get

func (arr *Array[T]) Get(index int) T

Get returns the element at the specified index. Negative indices are interpreted as relative to the end of the Array. Panics if the index is out of bounds.

func (*Array[T]) GetRef

func (arr *Array[T]) GetRef(index int) *T

GetRef returns a reference to the element at the specified index. Negative indices are interpreted as relative to the end of the Array. Panics if the index is out of bounds.

func (*Array[T]) Insert

func (arr *Array[T]) Insert(index int, value T)

Insert inserts the specified element at the specified index. Negative indices are interpreted as relative to the end of the Array. Panics if the index is out of bounds.

func (*Array[T]) InsertMany

func (arr *Array[T]) InsertMany(index int, values ...T)

InsertMany inserts the specified elements at the specified index. Negative indices are interpreted as relative to the end of the Array. Panics if the index is out of bounds.

func (*Array[T]) Iterator

func (arr *Array[T]) Iterator() iter.Iterator[T]

Iterator returns an iterator over the elements in the Array.

func (*Array[T]) Join

func (arr *Array[T]) Join(other cols.Collection[T])

Join appends all elements from the other collection to the Array. The other collection is cleared.

func (*Array[T]) Prepend

func (arr *Array[T]) Prepend(value T)

Prepend inserts the specified element at the beginning of the Array.

func (*Array[T]) PrependMany

func (arr *Array[T]) PrependMany(values ...T)

PrependMany inserts the specified elements at the beginning of the Array.

func (*Array[T]) RefsStream

func (arr *Array[T]) RefsStream(yield func(*T) bool)

RefsStream streams references to the elements in the Array.

func (*Array[T]) Remove

func (arr *Array[T]) Remove(index int)

Remove removes the element at the specified index. Negative indices are interpreted as relative to the end of the Array. Panics if the index is out of bounds.

func (*Array[T]) Reserve

func (arr *Array[T]) Reserve(additionalCapacity int)

Reserve reserves additional capacity for the Array. If additionalCapacity is negative, the function does nothing.

func (*Array[T]) Reverse

func (arr *Array[T]) Reverse()

Reverse reverses the order of the elements in the Array.

func (*Array[T]) Set

func (arr *Array[T]) Set(index int, value T)

Set sets the element at the specified index. Negative indices are interpreted as relative to the end of the Array. Panics if the index is out of bounds.

func (*Array[T]) Shrink

func (arr *Array[T]) Shrink()

Shrink shrinks the capacity of the Array to match its size.

func (*Array[T]) Size

func (arr *Array[T]) Size() int

Size returns the number of elements in the Array.

func (*Array[T]) Slice

func (arr *Array[T]) Slice() []T

Slice returns a slice of elements in the Array.

func (*Array[T]) SliceRange

func (arr *Array[T]) SliceRange(from, to int) []T

SliceRange returns a slice of elements in the Array in the specified range.

func (*Array[T]) Sort

func (arr *Array[T]) Sort(comparator comparison.Comparator[T])

Sort sorts the elements in the Array by the specified comparator. The sorting algorithm is stable.

func (*Array[T]) Stream

func (arr *Array[T]) Stream(yield func(T) bool)

Stream streams elements of the Array.

type Iterator

type Iterator[T any] struct {
	// contains filtered or unexported fields
}

Iterator is an iterator over an Array.

func (*Iterator[T]) Get

func (it *Iterator[T]) Get() T

Get returns the current element.

func (*Iterator[T]) GetRef

func (it *Iterator[T]) GetRef() *T

GetRef returns a reference to the current element.

func (*Iterator[T]) Index

func (it *Iterator[T]) Index() int

Index returns the current index.

func (*Iterator[T]) InsertAfter

func (it *Iterator[T]) InsertAfter(value T)

InsertAfter inserts the specified element after the current element. Iterator keeps pointing to the current element.

func (*Iterator[T]) InsertBefore

func (it *Iterator[T]) InsertBefore(value T)

InsertBefore inserts the specified element before the current element. Iterator then points to the inserted element.

func (*Iterator[T]) Move

func (it *Iterator[T]) Move()

Move moves the iterator to the next element.

func (*Iterator[T]) Remove

func (it *Iterator[T]) Remove()

Remove removes the current element. Iterator then points to the next element.

func (*Iterator[T]) Set

func (it *Iterator[T]) Set(value T)

Set sets the current element.

func (*Iterator[T]) Valid

func (it *Iterator[T]) Valid() bool

Valid returns true if the iterator is currently pointing to a valid element.

Jump to

Keyboard shortcuts

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