Documentation
¶
Index ¶
- func Append[E any, Alloc alloc.M](alloc Alloc, dst []E, elems ...E) []E
- func Compact[E any](s []E, eq func(s []E, prev, cur int) bool) []E
- func CompactEx[E, T any](s []E, arg T, eq func(arg T, s []E, prev, cur int) bool) []E
- func Cut[E any](s []E) (used, remaining []E)
- func Delete[E any](s []E, i, j int) []E
- func Grow[E any, Alloc alloc.M](alloc Alloc, s []E, n int) []E
- func Insert[E any, Alloc alloc.M](alloc Alloc, s []E, i int, v ...E) []E
- func Replace[E any, Alloc alloc.M](alloc Alloc, s []E, i, j int, v ...E) []E
- func Reverse[E any](s []E)
- func Split[Elem any](s []Elem) (arr *Elem, sz, kap int)
- type Header
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compact ¶
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 Delete ¶
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 ¶
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 ¶
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)).