stdslice

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append[E any, Alloc alloc.M](alloc Alloc, dst []E, elems ...E) []E

func Compact

func Compact[E any](s []E, eq func(s []E, prev, cur int) bool) []E

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 s and returns the modified slice, which may have a smaller length. When Compact discards m elements in total, it might not modify the elements s[len(s)-m:len(s)]. If those elements contain pointers you might consider zeroing those elements so that objects they reference can be garbage collected.

func CompactEx

func CompactEx[E, T any](s []E, arg T, eq func(arg T, s []E, prev, cur int) bool) []E

CompactEx is like Compact, but takes an extra arg.

func Cut

func Cut[E any](s []E) (used, remaining []E)

func Delete

func Delete[E any](s []E, i, j int) []E

Delete removes the elements s[i:j] from s, returning the modified slice. Delete panics if s[i:j] is not a valid slice of s. Delete is O(len(s)-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 s[len(s)-(j-i):len(s)]. If those elements contain pointers you might consider zeroing those elements so that objects they reference can be garbage collected.

func Grow

func Grow[E any, Alloc alloc.M](alloc Alloc, s []E, n int) []E

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 Insert

func Insert[E any, Alloc alloc.M](alloc Alloc, s []E, i int, v ...E) []E

Insert inserts the values v... into s at index i, returning the modified slice. The elements at s[i:] are shifted up to make room. In the returned slice r, r[i] == v[0], and r[i+len(v)] == value originally at r[i]. Insert panics if i is out of range. This function is O(len(s) + len(v)).

func Replace

func Replace[E any, Alloc alloc.M](alloc Alloc, s []E, i, j int, v ...E) []E

Replace replaces the elements s[i:j] by the given v, and returns the modified slice. Replace panics if s[i:j] is not a valid slice of s.

func Reverse

func Reverse[E any](s []E)

Reverse reverses the elements of the slice in place.

func Split

func Split[Elem any](s []Elem) (arr *Elem, sz, kap int)

Split returns actual members of a slice.

Types

type Header struct {
	Array unsafe.Pointer
	Len   int
	Cap   int
}

Jump to

Keyboard shortcuts

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