Documentation
¶
Index ¶
- func Clip[S ~[]E, E any](s S) S
- func Clone[S ~[]E, E any](s S) S
- func Compact[S ~[]E, E comparable](s S) S
- func CompactFunc[S ~[]E, E any](s S, eq func(E, E) bool) S
- func Contains[E comparable](s []E, v E) bool
- func ContainsFunc[E any](s []E, f func(E) bool) bool
- func Delete[S ~[]E, E any](s S, i, j int) S
- func Equal[E comparable](s1, s2 []E) bool
- func EqualFunc[E1, E2 any](s1 []E1, s2 []E2, eq func(E1, E2) bool) bool
- func FilterFunc[T comparable](s []T, callback func(val T) bool) []T
- func Grow[S ~[]E, E any](s S, n int) S
- func Index[E comparable](s []E, v E) int
- func IndexFunc[E any](s []E, f func(E) bool) int
- func Insert[S ~[]E, E any](s S, i int, v ...E) S
- func Process[E any](s []E, callback func(val E) E)
- func Replace[S ~[]E, E any](s S, i, j int, v ...E) S
- func SplitSliceByLimit[T any](s []T, limit int) [][]T
- func StringItemHasPrefix(s []string, prefix string) bool
- func StringItemHasSuffix(s []string, suffix string) bool
- func StringToSlice(s string, length int) []byte
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clip ¶
func Clip[S ~[]E, E any](s S) S
Clip removes unused capacity from the slice, returning s[:len(s):len(s)].
func Clone ¶
func Clone[S ~[]E, E any](s S) S
Clone returns a copy of the slice. The elements are copied using assignment, so this is a shallow clone.
func Compact ¶
func Compact[S ~[]E, E comparable](s S) S
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; it does not create a new slice. 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 CompactFunc ¶
CompactFunc is like Compact but uses a comparison function.
func Contains ¶
func Contains[E comparable](s []E, v E) bool
Contains reports whether v is present in s.
func ContainsFunc ¶
ContainsFunc reports whether at least one element e of s satisfies f(e).
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 modifies the contents of the slice s; it does not create a new slice. 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 Equal ¶
func Equal[E comparable](s1, s2 []E) bool
Equal reports whether two slices are equal: the same length and all elements equal. If the lengths are different, Equal returns false. Otherwise, the elements are compared in increasing index order, and the comparison stops at the first unequal pair. Floating point NaNs are not considered equal.
func EqualFunc ¶
EqualFunc reports whether two slices are equal using a comparison 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[E comparable](s []E, v E) int
Index returns the index of the first occurrence of v in s, or -1 if not present.
func IndexFunc ¶
IndexFunc 是一个泛型函数,用于在切片s中查找第一个满足函数f的元素,并返回其索引
参数:
@param E 是切片的元素类型, @param f 是一个接收E类型参数并返回bool值的函数
返回值:
@return int -1: 没有找到, >=0: 找到,返回索引值
func Insert ¶
Insert inserts the values v... into s at index i, returning the modified slice. In the returned slice r, r[i] == v[0]. Insert panics if i is out of range. This function is O(len(s) + len(v)).
func Replace ¶
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 SplitSliceByLimit ¶
@bref SplitSliceByLimit 将切片s按照指定的长度limit进行分割,返回分割后的二维切片
参数:
@param s:待分割的切片 @param limit:每个子切片的最大长度
返回值:
@return [][]T:分割后的二维切片
示例:
s := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
limit := 3
result := SplitSliceByLimit(s, limit)
fmt.Println(result) // 输出:[[1 2 3] [4 5 6] [7 8 9] [10]]
func StringItemHasPrefix ¶
StringItemHasPrefix 判断字符串切片 s 中是否存在以 prefix 为前缀的元素
参数:
@param s []string - 字符串切片 @param prefix string - 前缀字符串
返回值:
@return bool - 如果 s 中存在以 prefix 为前缀的元素,则返回 true;否则返回 false
func StringItemHasSuffix ¶
StringItemHasPrefix 判断字符串切片 s 中是否存在以 suffix 为后缀的元素
参数:
@param s []string - 字符串切片 @param suffix string - 后缀字符串
返回值:
@return bool - 如果 s 中存在以 suffix 为后缀的元素,则返回 true;否则返回 false
func StringToSlice ¶
获取 string的切片, 不足指定长度, 补0x0; 超过指定长度, 截取指定长度
Types ¶
This section is empty.