vRp.CD2g_test/utils/slice/zoom.go

12 lines
351 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package slice
// Zoom 将切片的长度缩放到指定的大小,如果 newSize 小于 slice 的长度,则会截断 slice如果 newSize 大于 slice 的长度,则会在 slice 的末尾添加零值数据
func Zoom[V any](newSize int, slice []V) []V {
if newSize < 0 {
newSize = 0
}
var s = make([]V, newSize)
copy(s, slice)
return s
}