Documentation
¶
Index ¶
- func Anys[T any](sa []T) []any
- func Clip[T any](a []T) []T
- func Clone[T any](a []T) []T
- func Compact[T comparable](a []T) []T
- func CompactFunc[T any](a []T, eq func(T, T) bool) []T
- func Contains[T comparable](a []T, c T) bool
- func ContainsFunc[T any](a []T, f func(T) bool) bool
- func Delete[T any](a []T, i, j int) []T
- func DeleteEqual[T comparable](a []T, e T) []T
- func DeleteFunc[T any](a []T, del func(T) bool) []T
- func Equal[T comparable](a []T, b []T) bool
- func EqualFunc[A any, B any](a []A, b []B, eq func(A, B) bool) bool
- func Get[T any](a []T, i int) (v T, ok bool)
- func Grow[T any](a []T, n int) []T
- func Index[T comparable](a []T, v T) int
- func IndexFunc[T any](a []T, f func(T) bool) int
- func Max[T any](a []T, less func(a []T, i, j int) bool) int
- func Min[T any](a []T, less func(a []T, i, j int) bool) int
- func Reverse[T any](a []T)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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 ¶
ContainsFunc reports whether at least one element e of a satisfies f(e).
func Delete ¶
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 ¶
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 ¶
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 Grow ¶
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.
Types ¶
This section is empty.