asg

package
v1.0.19 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2024 License: MIT Imports: 0 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Anys added in v1.0.15

func Anys[T any](sa []T) []any

Anys convert slice 'sa' to []any slice

func Clip

func Clip[T any](a []T) []T

Clip removes unused capacity from the slice, returning a[:len(a):len(a)].

func Clone

func Clone[T any](a []T) []T

Clone returns a copy of the slice. The elements are copied using assignment, so this is a shallow clone.

func Compact

func Compact[T comparable](a []T) []T

Compact replaces consecutive runs of equal elements with a single copy. This is like the uniq command found on Unix. Compact modifies the contents of the slice a and returns the modified slice, which may have a smaller length. When Compact discards m elements in total, it might not modify the elements a[len(a)-m:len(a)]. If those elements contain pointers you might consider zeroing those elements so that objects they reference can be garbage collected.

func CompactFunc

func CompactFunc[T any](a []T, eq func(T, T) bool) []T

CompactFunc is like Compact but uses an equality function to compare elements. For runs of elements that compare equal, CompactFunc keeps the first one.

func Contains

func Contains[T comparable](a []T, c T) bool

Contains reports whether the c is contained in the slice a.

func ContainsFunc

func ContainsFunc[T any](a []T, f func(T) bool) bool

ContainsFunc reports whether at least one element e of a satisfies f(e).

func Delete

func Delete[T any](a []T, i, j int) []T

Delete removes the elements a[i:j] from a, returning the modified slice. Delete panics if a[i:j] is not a valid slice of a. Delete is O(len(a)-j), so if many items must be deleted, it is better to make a single call deleting them all together than to delete one at a time. Delete might not modify the elements a[len(a)-(j-i):len(a)]. If those elements contain pointers you might consider zeroing those elements so that objects they reference can be garbage collected.

func DeleteEqual added in v1.0.13

func DeleteEqual[T comparable](a []T, e T) []T

DeleteEqual removes any elements from a for which elemant == e, returning the modified slice. When DeleteFunc removes m elements, it might not modify the elements a[len(a)-m:len(a)]. If those elements contain pointers you might consider zeroing those elements so that objects they reference can be garbage collected.

func DeleteFunc

func DeleteFunc[T any](a []T, del func(T) bool) []T

DeleteFunc removes any elements from a for which del returns true, returning the modified slice. When DeleteFunc removes m elements, it might not modify the elements a[len(a)-m:len(a)]. If those elements contain pointers you might consider zeroing those elements so that objects they reference can be garbage collected.

func Equal

func Equal[T comparable](a []T, b []T) bool

Equal reports whether a and b are the same length and contain the same element. A nil argument is equivalent to an empty slice.

func EqualFunc

func EqualFunc[A any, B any](a []A, b []B, eq func(A, B) bool) bool

EqualFunc reports whether two slices are equal using an equality function on each pair of elements. If the lengths are different, EqualFunc returns false. Otherwise, the elements are compared in increasing index order, and the comparison stops at the first index for which eq returns false.

func Get

func Get[T any](a []T, i int) (v T, ok bool)

Get get element at the specified index i.

func Grow

func Grow[T any](a []T, n int) []T

Grow increases the slice's capacity, if necessary, to guarantee space for another n elements. After Grow(n), at least n elements can be appended to the slice without another allocation. If n is negative or too large to allocate the memory, Grow panics.

func Index

func Index[T comparable](a []T, v T) int

Index returns the index of the first instance of v in a, or -1 if v is not present in a.

func IndexFunc

func IndexFunc[T any](a []T, f func(T) bool) int

IndexFunc returns the first index i satisfying f(a[i]), or -1 if none do.

func Reverse

func Reverse[T any](a []T)

Reverse reverses the elements of the slice in place.

Types

This section is empty.

Jump to

Keyboard shortcuts

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