sortpkg

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

README

sort

排序辅助函数,包含基础类型和泛型排序。

基础用法

sortpkg.Sort(values)
sortpkg.SortFunc(users, func(a, b User) int {
	return cmp.Compare(a.ID, b.ID)
})

注意事项

确认函数是否原地修改切片,避免调用方误用共享切片。

验证

go test ./sort

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Int32s deprecated

func Int32s(s []int32)

Deprecated: 使用 Sort[int32] 替代

func Int64s deprecated

func Int64s(s []int64)

Deprecated: 使用 Sort[int64] 替代

func Sort

func Sort[T cmp.Ordered](s []T)

Sort 对有序类型切片排序

func SortFunc

func SortFunc[T any](s []T, less func(a, b T) int)

SortFunc 使用自定义比较函数排序

Types

type Int32Slice deprecated

type Int32Slice []int32

Deprecated: 使用 Sort[int32] 替代

func (Int32Slice) Len

func (p Int32Slice) Len() int

func (Int32Slice) Less

func (p Int32Slice) Less(i, j int) bool

func (Int32Slice) Swap

func (p Int32Slice) Swap(i, j int)

type Int64Slice deprecated

type Int64Slice []int64

Deprecated: 使用 Sort[int64] 替代

func (Int64Slice) Len

func (p Int64Slice) Len() int

func (Int64Slice) Less

func (p Int64Slice) Less(i, j int) bool

func (Int64Slice) Swap

func (p Int64Slice) Swap(i, j int)

Jump to

Keyboard shortcuts

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