From a026e4cf965ffa2390ac86a29478f609ceab23a3 Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Mon, 15 Jan 2024 10:54:27 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E4=BC=98=E5=8C=96=20README.md=20?= =?UTF-8?q?=E5=8C=85=E7=BA=A7=E5=87=BD=E6=95=B0=E4=B8=8D=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=B3=9B=E5=9E=8B=E7=AD=BE=E5=90=8D=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/activity/README.md | 34 ++-- game/fight/README.md | 2 +- game/space/README.md | 4 +- game/task/README.md | 4 +- server/README.md | 4 +- server/internal/dispatcher/README.md | 4 +- server/lockstep/README.md | 10 +- server/router/README.md | 4 +- server/writeloop/README.md | 4 +- utils/aoi/README.md | 2 +- utils/arrangement/README.md | 20 +-- utils/buffer/README.md | 6 +- utils/collection/README.md | 233 ++++++++++++++------------- utils/collection/clone.go | 5 +- utils/collection/doc.go | 2 +- utils/collection/listings/README.md | 8 +- utils/collection/mappings/README.md | 2 +- utils/combination/README.md | 60 +++---- utils/deck/README.md | 4 +- utils/fsm/README.md | 12 +- utils/generator/genreadme/builder.go | 18 ++- utils/generic/README.md | 6 +- utils/geometry/README.md | 150 ++++++++--------- utils/geometry/astar/README.md | 2 +- utils/geometry/dp/README.md | 2 +- utils/geometry/matrix/README.md | 2 +- utils/geometry/navmesh/README.md | 2 +- utils/hub/README.md | 2 +- utils/huge/README.md | 4 +- utils/leaderboard/README.md | 6 +- utils/log/README.md | 52 +++--- utils/maths/README.md | 38 ++--- utils/memory/README.md | 4 +- utils/moving/README.md | 8 +- utils/random/README.md | 12 +- utils/reflects/README.md | 10 +- utils/sole/README.md | 2 +- utils/sorts/README.md | 2 +- utils/super/README.md | 18 +-- utils/times/README.md | 2 +- 40 files changed, 389 insertions(+), 377 deletions(-) diff --git a/game/activity/README.md b/game/activity/README.md index 85c9360..0147d77 100644 --- a/game/activity/README.md +++ b/game/activity/README.md @@ -75,88 +75,88 @@ activity 活动状态管理 > 加载所有活动实体数据 *** -#### func LoadOrRefreshActivity(activityType Type, activityId ID, options ...*Options) error +#### func LoadOrRefreshActivity\[Type generic.Basic, ID generic.Basic\](activityType Type, activityId ID, options ...*Options) error > 加载或刷新活动 > - 通常在活动配置刷新时候将活动通过该方法注册或刷新 *** -#### func DefineNoneDataActivity(activityType Type) NoneDataActivityController[Type, ID, *none, none, *none] +#### func DefineNoneDataActivity\[Type generic.Basic, ID generic.Basic\](activityType Type) NoneDataActivityController[Type, ID, *none, none, *none] > 声明无数据的活动类型 *** -#### func DefineGlobalDataActivity(activityType Type) GlobalDataActivityController[Type, ID, Data, none, *none] +#### func DefineGlobalDataActivity\[Type generic.Basic, ID generic.Basic, Data any\](activityType Type) GlobalDataActivityController[Type, ID, Data, none, *none] > 声明拥有全局数据的活动类型 *** -#### func DefineEntityDataActivity(activityType Type) EntityDataActivityController[Type, ID, *none, EntityID, EntityData] +#### func DefineEntityDataActivity\[Type generic.Basic, ID generic.Basic, EntityID generic.Basic, EntityData any\](activityType Type) EntityDataActivityController[Type, ID, *none, EntityID, EntityData] > 声明拥有实体数据的活动类型 *** -#### func DefineGlobalAndEntityDataActivity(activityType Type) GlobalAndEntityDataActivityController[Type, ID, Data, EntityID, EntityData] +#### func DefineGlobalAndEntityDataActivity\[Type generic.Basic, ID generic.Basic, Data any, EntityID generic.Basic, EntityData any\](activityType Type) GlobalAndEntityDataActivityController[Type, ID, Data, EntityID, EntityData] > 声明拥有全局数据和实体数据的活动类型 *** -#### func RegUpcomingEvent(activityType Type, handler UpcomingEventHandler[ID], priority ...int) +#### func RegUpcomingEvent\[Type generic.Basic, ID generic.Basic\](activityType Type, handler UpcomingEventHandler[ID], priority ...int) > 注册即将开始的活动事件处理器 *** -#### func OnUpcomingEvent(activity *Activity[Type, ID]) +#### func OnUpcomingEvent\[Type generic.Basic, ID generic.Basic\](activity *Activity[Type, ID]) > 即将开始的活动事件 *** -#### func RegStartedEvent(activityType Type, handler StartedEventHandler[ID], priority ...int) +#### func RegStartedEvent\[Type generic.Basic, ID generic.Basic\](activityType Type, handler StartedEventHandler[ID], priority ...int) > 注册活动开始事件处理器 *** -#### func OnStartedEvent(activity *Activity[Type, ID]) +#### func OnStartedEvent\[Type generic.Basic, ID generic.Basic\](activity *Activity[Type, ID]) > 活动开始事件 *** -#### func RegEndedEvent(activityType Type, handler EndedEventHandler[ID], priority ...int) +#### func RegEndedEvent\[Type generic.Basic, ID generic.Basic\](activityType Type, handler EndedEventHandler[ID], priority ...int) > 注册活动结束事件处理器 *** -#### func OnEndedEvent(activity *Activity[Type, ID]) +#### func OnEndedEvent\[Type generic.Basic, ID generic.Basic\](activity *Activity[Type, ID]) > 活动结束事件 *** -#### func RegExtendedShowStartedEvent(activityType Type, handler ExtendedShowStartedEventHandler[ID], priority ...int) +#### func RegExtendedShowStartedEvent\[Type generic.Basic, ID generic.Basic\](activityType Type, handler ExtendedShowStartedEventHandler[ID], priority ...int) > 注册活动结束后延长展示开始事件处理器 *** -#### func OnExtendedShowStartedEvent(activity *Activity[Type, ID]) +#### func OnExtendedShowStartedEvent\[Type generic.Basic, ID generic.Basic\](activity *Activity[Type, ID]) > 活动结束后延长展示开始事件 *** -#### func RegExtendedShowEndedEvent(activityType Type, handler ExtendedShowEndedEventHandler[ID], priority ...int) +#### func RegExtendedShowEndedEvent\[Type generic.Basic, ID generic.Basic\](activityType Type, handler ExtendedShowEndedEventHandler[ID], priority ...int) > 注册活动结束后延长展示结束事件处理器 *** -#### func OnExtendedShowEndedEvent(activity *Activity[Type, ID]) +#### func OnExtendedShowEndedEvent\[Type generic.Basic, ID generic.Basic\](activity *Activity[Type, ID]) > 活动结束后延长展示结束事件 *** -#### func RegNewDayEvent(activityType Type, handler NewDayEventHandler[ID], priority ...int) +#### func RegNewDayEvent\[Type generic.Basic, ID generic.Basic\](activityType Type, handler NewDayEventHandler[ID], priority ...int) > 注册新的一天事件处理器 *** -#### func OnNewDayEvent(activity *Activity[Type, ID]) +#### func OnNewDayEvent\[Type generic.Basic, ID generic.Basic\](activity *Activity[Type, ID]) > 新的一天事件 diff --git a/game/fight/README.md b/game/fight/README.md index 8f4bb3e..14ceab1 100644 --- a/game/fight/README.md +++ b/game/fight/README.md @@ -34,7 +34,7 @@ *** ## 详情信息 -#### func NewTurnBased(calcNextTurnDuration func ( Camp, Entity) time.Duration) *TurnBased[CampID, EntityID, Camp, Entity] +#### func NewTurnBased\[CampID comparable, EntityID comparable, Camp generic.IdR[CampID], Entity generic.IdR[EntityID]\](calcNextTurnDuration func ( Camp, Entity) time.Duration) *TurnBased[CampID, EntityID, Camp, Entity] > 创建一个新的回合制 > - calcNextTurnDuration 将返回下一次行动时间间隔,适用于按照速度计算下一次行动时间间隔的情况。当返回 0 时,将使用默认的行动超时时间 diff --git a/game/space/README.md b/game/space/README.md index 1e3542f..4b239fb 100644 --- a/game/space/README.md +++ b/game/space/README.md @@ -34,7 +34,7 @@ space 游戏中常见的空间设计,例如房间、地图等 *** ## 详情信息 -#### func NewRoomManager() *RoomManager[EntityID, RoomID, Entity, Room] +#### func NewRoomManager\[EntityID comparable, RoomID comparable, Entity generic.IdR[EntityID], Room generic.IdR[RoomID]\]() *RoomManager[EntityID, RoomID, Entity, Room] > 创建房间管理器 RoomManager 的实例 @@ -49,7 +49,7 @@ func ExampleNewRoomManager() { ``` *** -#### func NewRoomControllerOptions() *RoomControllerOptions[EntityID, RoomID, Entity, Room] +#### func NewRoomControllerOptions\[EntityID comparable, RoomID comparable, Entity generic.IdR[EntityID], Room generic.IdR[RoomID]\]() *RoomControllerOptions[EntityID, RoomID, Entity, Room] > 创建房间控制器选项 diff --git a/game/task/README.md b/game/task/README.md index a86db7e..58902de 100644 --- a/game/task/README.md +++ b/game/task/README.md @@ -88,7 +88,7 @@ func TestCond(t *testing.T) { *** -#### func RegisterRefreshTaskCounterEvent(taskType string, handler RefreshTaskCounterEventHandler[Trigger]) +#### func RegisterRefreshTaskCounterEvent\[Trigger any\](taskType string, handler RefreshTaskCounterEventHandler[Trigger]) > 注册特定任务类型的刷新任务计数器事件处理函数 @@ -98,7 +98,7 @@ func TestCond(t *testing.T) { > 触发特定任务类型的刷新任务计数器事件 *** -#### func RegisterRefreshTaskConditionEvent(taskType string, handler RefreshTaskConditionEventHandler[Trigger]) +#### func RegisterRefreshTaskConditionEvent\[Trigger any\](taskType string, handler RefreshTaskConditionEventHandler[Trigger]) > 注册特定任务类型的刷新任务条件事件处理函数 diff --git a/server/README.md b/server/README.md index d048f66..80226cc 100644 --- a/server/README.md +++ b/server/README.md @@ -138,7 +138,7 @@ func TestNewBot(t *testing.T) { *** -#### func NewHttpHandleWrapper(srv *Server, packer ContextPacker[Context]) *Http[Context] +#### func NewHttpHandleWrapper\[Context any\](srv *Server, packer ContextPacker[Context]) *Http[Context] > 创建一个新的 http 处理程序包装器 > - 默认使用 server.HttpContext 作为上下文,如果需要依赖其作为新的上下文,可以通过 NewHttpContext 创建 @@ -149,7 +149,7 @@ func TestNewBot(t *testing.T) { > 基于 gin.Context 创建一个新的 HttpContext *** -#### func NewGinWrapper(server *gin.Engine, pack func (ctx *gin.Context) CTX) *HttpWrapper[CTX] +#### func NewGinWrapper\[CTX any\](server *gin.Engine, pack func (ctx *gin.Context) CTX) *HttpWrapper[CTX] > 创建 gin 包装器,用于对 NewHttpWrapper 函数的替代 diff --git a/server/internal/dispatcher/README.md b/server/internal/dispatcher/README.md index 1c6e6a5..3948e8b 100644 --- a/server/internal/dispatcher/README.md +++ b/server/internal/dispatcher/README.md @@ -36,7 +36,7 @@ *** ## 详情信息 -#### func NewDispatcher(bufferSize int, name string, handler Handler[P, M]) *Dispatcher[P, M] +#### func NewDispatcher\[P Producer, M Message[P]\](bufferSize int, name string, handler Handler[P, M]) *Dispatcher[P, M] > 创建一个新的消息分发器 Dispatcher 实例 @@ -107,7 +107,7 @@ func TestNewDispatcher(t *testing.T) { *** -#### func NewManager(bufferSize int, handler Handler[P, M]) *Manager[P, M] +#### func NewManager\[P Producer, M Message[P]\](bufferSize int, handler Handler[P, M]) *Manager[P, M] > 生成消息分发器管理器 diff --git a/server/lockstep/README.md b/server/lockstep/README.md index 4f9f147..e0a6a48 100644 --- a/server/lockstep/README.md +++ b/server/lockstep/README.md @@ -37,7 +37,7 @@ *** ## 详情信息 -#### func NewLockstep(options ...Option[ClientID, Command]) *Lockstep[ClientID, Command] +#### func NewLockstep\[ClientID comparable, Command any\](options ...Option[ClientID, Command]) *Lockstep[ClientID, Command] > 创建一个锁步(帧)同步默认实现的组件(Lockstep)进行返回 @@ -78,19 +78,19 @@ func TestNewLockstep(t *testing.T) { *** -#### func WithFrameLimit(frameLimit int64) Option[ClientID, Command] +#### func WithFrameLimit\[ClientID comparable, Command any\](frameLimit int64) Option[ClientID, Command] > 通过特定逻辑帧上限创建锁步(帧)同步组件 > - 当达到上限时将停止广播 *** -#### func WithFrameRate(frameRate int64) Option[ClientID, Command] +#### func WithFrameRate\[ClientID comparable, Command any\](frameRate int64) Option[ClientID, Command] > 通过特定逻辑帧率创建锁步(帧)同步组件 > - 默认情况下为 15/s *** -#### func WithSerialization(handle func (frame int64, commands []Command) []byte) Option[ClientID, Command] +#### func WithSerialization\[ClientID comparable, Command any\](handle func (frame int64, commands []Command) []byte) Option[ClientID, Command] > 通过特定的序列化方式将每一帧的数据进行序列化 > @@ -102,7 +102,7 @@ func TestNewLockstep(t *testing.T) { > } *** -#### func WithInitFrame(initFrame int64) Option[ClientID, Command] +#### func WithInitFrame\[ClientID comparable, Command any\](initFrame int64) Option[ClientID, Command] > 通过特定的初始帧创建锁步(帧)同步组件 > - 默认情况下为 0,即第一帧索引为 0 diff --git a/server/router/README.md b/server/router/README.md index aa0095f..56e4248 100644 --- a/server/router/README.md +++ b/server/router/README.md @@ -33,7 +33,7 @@ *** ## 详情信息 -#### func NewMultistage(options ...MultistageOption[HandleFunc]) *Multistage[HandleFunc] +#### func NewMultistage\[HandleFunc any\](options ...MultistageOption[HandleFunc]) *Multistage[HandleFunc] > 创建一个支持多级分类的路由器 @@ -47,7 +47,7 @@ func ExampleNewMultistage() { ``` *** -#### func WithRouteTrim(handle func (route any) any) MultistageOption[HandleFunc] +#### func WithRouteTrim\[HandleFunc any\](handle func (route any) any) MultistageOption[HandleFunc] > 路由修剪选项 > - 将在路由注册前对路由进行对应处理 diff --git a/server/writeloop/README.md b/server/writeloop/README.md index 42f8feb..3b4d67b 100644 --- a/server/writeloop/README.md +++ b/server/writeloop/README.md @@ -33,7 +33,7 @@ *** ## 详情信息 -#### func NewChannel(pool *hub.ObjectPool[Message], channelSize int, writeHandler func (message Message) error, errorHandler func (err any)) *Channel[Message] +#### func NewChannel\[Message any\](pool *hub.ObjectPool[Message], channelSize int, writeHandler func (message Message) error, errorHandler func (err any)) *Channel[Message] > 创建基于 Channel 的写循环 > - pool 用于管理 Message 对象的缓冲池,在创建 Message 对象时也应该使用该缓冲池,以便复用 Message 对象。 Channel 会在写入完成后将 Message 对象放回缓冲池 @@ -44,7 +44,7 @@ > 传入 writeHandler 的消息对象是从 Channel 中获取的,因此 writeHandler 不应该持有消息对象的引用,同时也不应该主动释放消息对象 *** -#### func NewUnbounded(pool *hub.ObjectPool[Message], writeHandler func (message Message) error, errorHandler func (err any)) *Unbounded[Message] +#### func NewUnbounded\[Message any\](pool *hub.ObjectPool[Message], writeHandler func (message Message) error, errorHandler func (err any)) *Unbounded[Message] > 创建写循环 > - pool 用于管理 Message 对象的缓冲池,在创建 Message 对象时也应该使用该缓冲池,以便复用 Message 对象。 Unbounded 会在写入完成后将 Message 对象放回缓冲池 diff --git a/utils/aoi/README.md b/utils/aoi/README.md index 02bc926..ba1f75c 100644 --- a/utils/aoi/README.md +++ b/utils/aoi/README.md @@ -37,7 +37,7 @@ AOI 问题是在大规模多人在线游戏中常见的问题,它涉及到确 *** ## 详情信息 -#### func NewTwoDimensional(width int, height int, areaWidth int, areaHeight int) *TwoDimensional[EID, PosType, E] +#### func NewTwoDimensional\[EID generic.Basic, PosType generic.SignedNumber, E TwoDimensionalEntity[EID, PosType]\](width int, height int, areaWidth int, areaHeight int) *TwoDimensional[EID, PosType, E]
diff --git a/utils/arrangement/README.md b/utils/arrangement/README.md index e06b770..e5feb02 100644 --- a/utils/arrangement/README.md +++ b/utils/arrangement/README.md @@ -50,54 +50,54 @@ arrangement 包提供了一些有用的函数来处理数组的排列。 *** ## 详情信息 -#### func WithAreaConstraint(constraint AreaConstraintHandle[ID, AreaInfo]) AreaOption[ID, AreaInfo] +#### func WithAreaConstraint\[ID comparable, AreaInfo any\](constraint AreaConstraintHandle[ID, AreaInfo]) AreaOption[ID, AreaInfo] > 设置编排区域的约束条件 > - 该约束用于判断一个成员是否可以被添加到该编排区域中 > - 与 WithAreaConflict 不同的是,约束通常用于非成员关系导致的硬性约束,例如:成员的等级过滤、成员的性别等 *** -#### func WithAreaConflict(conflict AreaConflictHandle[ID, AreaInfo]) AreaOption[ID, AreaInfo] +#### func WithAreaConflict\[ID comparable, AreaInfo any\](conflict AreaConflictHandle[ID, AreaInfo]) AreaOption[ID, AreaInfo] > 设置编排区域的冲突条件,冲突处理函数需要返回造成冲突的成员列表 > - 该冲突用于判断一个成员是否可以被添加到该编排区域中 > - 与 WithAreaConstraint 不同的是,冲突通常用于成员关系导致的软性约束,例如:成员的职业唯一性、成员的种族唯一性等 *** -#### func WithAreaEvaluate(evaluate AreaEvaluateHandle[ID, AreaInfo]) AreaOption[ID, AreaInfo] +#### func WithAreaEvaluate\[ID comparable, AreaInfo any\](evaluate AreaEvaluateHandle[ID, AreaInfo]) AreaOption[ID, AreaInfo] > 设置编排区域的评估函数 > - 该评估函数将影响成员被编入区域的优先级 *** -#### func NewArrangement(options ...Option[ID, AreaInfo]) *Arrangement[ID, AreaInfo] +#### func NewArrangement\[ID comparable, AreaInfo any\](options ...Option[ID, AreaInfo]) *Arrangement[ID, AreaInfo] > 创建一个新的编排 *** -#### func WithItemFixed(matcher ItemFixedAreaHandle[AreaInfo]) ItemOption[ID, AreaInfo] +#### func WithItemFixed\[ID comparable, AreaInfo any\](matcher ItemFixedAreaHandle[AreaInfo]) ItemOption[ID, AreaInfo] > 设置成员的固定编排区域 *** -#### func WithItemPriority(priority ItemPriorityHandle[ID, AreaInfo]) ItemOption[ID, AreaInfo] +#### func WithItemPriority\[ID comparable, AreaInfo any\](priority ItemPriorityHandle[ID, AreaInfo]) ItemOption[ID, AreaInfo] > 设置成员的优先级 *** -#### func WithItemNotAllow(verify ItemNotAllowVerifyHandle[ID, AreaInfo]) ItemOption[ID, AreaInfo] +#### func WithItemNotAllow\[ID comparable, AreaInfo any\](verify ItemNotAllowVerifyHandle[ID, AreaInfo]) ItemOption[ID, AreaInfo] > 设置成员不允许的编排区域 *** -#### func WithRetryThreshold(threshold int) Option[ID, AreaInfo] +#### func WithRetryThreshold\[ID comparable, AreaInfo any\](threshold int) Option[ID, AreaInfo] > 设置编排时的重试阈值 > - 当每一轮编排结束任有成员未被编排时,将会进行下一轮编排,直到编排次数达到该阈值 > - 默认的阈值为 10 次 *** -#### func WithConstraintHandle(handle ConstraintHandle[ID, AreaInfo]) Option[ID, AreaInfo] +#### func WithConstraintHandle\[ID comparable, AreaInfo any\](handle ConstraintHandle[ID, AreaInfo]) Option[ID, AreaInfo] > 设置编排时触发约束时的处理函数 > - 当约束条件触发时,将会调用该函数。如果无法在该函数中处理约束,应该继续返回 err,尝试进行下一层的约束处理 @@ -107,7 +107,7 @@ arrangement 包提供了一些有用的函数来处理数组的排列。 > 有意思的是,硬性约束应该永远是无解的,而当需要进行一些打破规则的操作时,则可以透过该函数传入的 editor 进行操作 *** -#### func WithConflictHandle(handle ConflictHandle[ID, AreaInfo]) Option[ID, AreaInfo] +#### func WithConflictHandle\[ID comparable, AreaInfo any\](handle ConflictHandle[ID, AreaInfo]) Option[ID, AreaInfo] > 设置编排时触发冲突时的处理函数 > - 当冲突条件触发时,将会调用该函数。如果无法在该函数中处理冲突,应该继续返回这一批成员,尝试进行下一层的冲突处理 diff --git a/utils/buffer/README.md b/utils/buffer/README.md index b96e2b3..1470178 100644 --- a/utils/buffer/README.md +++ b/utils/buffer/README.md @@ -40,7 +40,7 @@ buffer 提供了缓冲区相关的实用程序。 *** ## 详情信息 -#### func NewRing(initSize ...int) *Ring[T] +#### func NewRing\[T any\](initSize ...int) *Ring[T] > 创建一个并发不安全的环形缓冲区 > - initSize: 初始容量 @@ -68,12 +68,12 @@ func TestNewRing(t *testing.T) { *** -#### func NewRingUnbounded(bufferSize int) *RingUnbounded[T] +#### func NewRingUnbounded\[T any\](bufferSize int) *RingUnbounded[T] > 创建一个并发安全的基于环形缓冲区实现的无界缓冲区 *** -#### func NewUnbounded() *Unbounded[V] +#### func NewUnbounded\[V any\]() *Unbounded[V] > 创建一个无界缓冲区 > - generateNil: 生成空值的函数,该函数仅需始终返回 nil 即可 diff --git a/utils/collection/README.md b/utils/collection/README.md index 4850246..5c3a13c 100644 --- a/utils/collection/README.md +++ b/utils/collection/README.md @@ -3,7 +3,7 @@ [![Go doc](https://img.shields.io/badge/go.dev-reference-brightgreen?logo=go&logoColor=white&style=flat)](https://pkg.go.dev/github.com/kercylan98/minotaur) ![](https://img.shields.io/badge/Email-kercylan@gmail.com-green.svg?style=flat) -collection 用于对 input 和 map 操作的工具函数 +collection 定义了各种对于集合操作有用的各种函数 ## 目录导航 @@ -16,8 +16,8 @@ collection 用于对 input 和 map 操作的工具函数 |函数名称|描述 |:--|:-- -|[CloneSlice](#CloneSlice)|克隆切片,该函数是 slices.Clone 的快捷方式 -|[CloneMap](#CloneMap)|克隆 map +|[CloneSlice](#CloneSlice)|通过创建一个新切片并将 slice 的元素复制到新切片的方式来克隆切片 +|[CloneMap](#CloneMap)|通过创建一个新 map 并将 m 的元素复制到新 map 的方式来克隆 map |[CloneSliceN](#CloneSliceN)|克隆 slice 为 n 个切片进行返回 |[CloneMapN](#CloneMapN)|克隆 map 为 n 个 map 进行返回 |[CloneSlices](#CloneSlices)|克隆多个切片 @@ -141,9 +141,9 @@ collection 用于对 input 和 map 操作的工具函数 *** ## 详情信息 -#### func CloneSlice(slice S) S +#### func CloneSlice\[S ~[]V, V any\](slice S) S -> 克隆切片,该函数是 slices.Clone 的快捷方式 +> 通过创建一个新切片并将 slice 的元素复制到新切片的方式来克隆切片 示例代码: ```go @@ -190,9 +190,10 @@ func TestCloneSlice(t *testing.T) { *** -#### func CloneMap(m M) M +#### func CloneMap\[M ~map[K]V, K comparable, V any\](m M) M -> 克隆 map +> 通过创建一个新 map 并将 m 的元素复制到新 map 的方式来克隆 map +> - 当 m 为空时,将会返回 nil 示例代码: ```go @@ -239,7 +240,7 @@ func TestCloneMap(t *testing.T) { *** -#### func CloneSliceN(slice S, n int) []S +#### func CloneSliceN\[S ~[]V, V any\](slice S, n int) []S > 克隆 slice 为 n 个切片进行返回 @@ -294,7 +295,7 @@ func TestCloneSliceN(t *testing.T) { *** -#### func CloneMapN(m M, n int) []M +#### func CloneMapN\[M ~map[K]V, K comparable, V any\](m M, n int) []M > 克隆 map 为 n 个 map 进行返回 @@ -349,7 +350,7 @@ func TestCloneMapN(t *testing.T) { *** -#### func CloneSlices(slices ...S) []S +#### func CloneSlices\[S ~[]V, V any\](slices ...S) []S > 克隆多个切片 @@ -401,7 +402,7 @@ func TestCloneSlices(t *testing.T) { *** -#### func CloneMaps(maps ...M) []M +#### func CloneMaps\[M ~map[K]V, K comparable, V any\](maps ...M) []M > 克隆多个 map @@ -453,7 +454,7 @@ func TestCloneMaps(t *testing.T) { *** -#### func InSlice(slice S, v V, handler ComparisonHandler[V]) bool +#### func InSlice\[S ~[]V, V any\](slice S, v V, handler ComparisonHandler[V]) bool > 检查 v 是否被包含在 slice 中,当 handler 返回 true 时,表示 v 和 slice 中的某个元素相匹配 @@ -501,7 +502,7 @@ func TestInSlice(t *testing.T) { *** -#### func InComparableSlice(slice S, v V) bool +#### func InComparableSlice\[S ~[]V, V comparable\](slice S, v V) bool > 检查 v 是否被包含在 slice 中 @@ -545,7 +546,7 @@ func TestInComparableSlice(t *testing.T) { *** -#### func AllInSlice(slice S, values []V, handler ComparisonHandler[V]) bool +#### func AllInSlice\[S ~[]V, V any\](slice S, values []V, handler ComparisonHandler[V]) bool > 检查 values 中的所有元素是否均被包含在 slice 中,当 handler 返回 true 时,表示 values 中的某个元素和 slice 中的某个元素相匹配 > - 在所有 values 中的元素都被包含在 slice 中时,返回 true @@ -595,7 +596,7 @@ func TestAllInSlice(t *testing.T) { *** -#### func AllInComparableSlice(slice S, values []V) bool +#### func AllInComparableSlice\[S ~[]V, V comparable\](slice S, values []V) bool > 检查 values 中的所有元素是否均被包含在 slice 中 > - 在所有 values 中的元素都被包含在 slice 中时,返回 true @@ -641,7 +642,7 @@ func TestAllInComparableSlice(t *testing.T) { *** -#### func AnyInSlice(slice S, values []V, handler ComparisonHandler[V]) bool +#### func AnyInSlice\[S ~[]V, V any\](slice S, values []V, handler ComparisonHandler[V]) bool > 检查 values 中的任意一个元素是否被包含在 slice 中,当 handler 返回 true 时,表示 value 中的某个元素和 slice 中的某个元素相匹配 > - 当 values 中的任意一个元素被包含在 slice 中时,返回 true @@ -690,7 +691,7 @@ func TestAnyInSlice(t *testing.T) { *** -#### func AnyInComparableSlice(slice S, values []V) bool +#### func AnyInComparableSlice\[S ~[]V, V comparable\](slice S, values []V) bool > 检查 values 中的任意一个元素是否被包含在 slice 中 > - 当 values 中的任意一个元素被包含在 slice 中时,返回 true @@ -735,7 +736,7 @@ func TestAnyInComparableSlice(t *testing.T) { *** -#### func InSlices(slices []S, v V, handler ComparisonHandler[V]) bool +#### func InSlices\[S ~[]V, V any\](slices []S, v V, handler ComparisonHandler[V]) bool > 通过将多个切片合并后检查 v 是否被包含在 slices 中,当 handler 返回 true 时,表示 v 和 slices 中的某个元素相匹配 > - 当传入的 v 被包含在 slices 的任一成员中时,返回 true @@ -784,7 +785,7 @@ func TestInSlices(t *testing.T) { *** -#### func InComparableSlices(slices []S, v V) bool +#### func InComparableSlices\[S ~[]V, V comparable\](slices []S, v V) bool > 通过将多个切片合并后检查 v 是否被包含在 slices 中 > - 当传入的 v 被包含在 slices 的任一成员中时,返回 true @@ -829,7 +830,7 @@ func TestInComparableSlices(t *testing.T) { *** -#### func AllInSlices(slices []S, values []V, handler ComparisonHandler[V]) bool +#### func AllInSlices\[S ~[]V, V any\](slices []S, values []V, handler ComparisonHandler[V]) bool > 通过将多个切片合并后检查 values 中的所有元素是否被包含在 slices 中,当 handler 返回 true 时,表示 values 中的某个元素和 slices 中的某个元素相匹配 > - 当 values 中的所有元素都被包含在 slices 的任一成员中时,返回 true @@ -878,7 +879,7 @@ func TestAllInSlices(t *testing.T) { *** -#### func AllInComparableSlices(slices []S, values []V) bool +#### func AllInComparableSlices\[S ~[]V, V comparable\](slices []S, values []V) bool > 通过将多个切片合并后检查 values 中的所有元素是否被包含在 slices 中 > - 当 values 中的所有元素都被包含在 slices 的任一成员中时,返回 true @@ -923,7 +924,7 @@ func TestAllInComparableSlices(t *testing.T) { *** -#### func AnyInSlices(slices []S, values []V, handler ComparisonHandler[V]) bool +#### func AnyInSlices\[S ~[]V, V any\](slices []S, values []V, handler ComparisonHandler[V]) bool > 通过将多个切片合并后检查 values 中的任意一个元素是否被包含在 slices 中,当 handler 返回 true 时,表示 values 中的某个元素和 slices 中的某个元素相匹配 > - 当 values 中的任意一个元素被包含在 slices 的任一成员中时,返回 true @@ -972,7 +973,7 @@ func TestAnyInSlices(t *testing.T) { *** -#### func AnyInComparableSlices(slices []S, values []V) bool +#### func AnyInComparableSlices\[S ~[]V, V comparable\](slices []S, values []V) bool > 通过将多个切片合并后检查 values 中的任意一个元素是否被包含在 slices 中 > - 当 values 中的任意一个元素被包含在 slices 的任一成员中时,返回 true @@ -1017,7 +1018,7 @@ func TestAnyInComparableSlices(t *testing.T) { *** -#### func InAllSlices(slices []S, v V, handler ComparisonHandler[V]) bool +#### func InAllSlices\[S ~[]V, V any\](slices []S, v V, handler ComparisonHandler[V]) bool > 检查 v 是否被包含在 slices 的每一项元素中,当 handler 返回 true 时,表示 v 和 slices 中的某个元素相匹配 > - 当 v 被包含在 slices 的每一项元素中时,返回 true @@ -1066,7 +1067,7 @@ func TestInAllSlices(t *testing.T) { *** -#### func InAllComparableSlices(slices []S, v V) bool +#### func InAllComparableSlices\[S ~[]V, V comparable\](slices []S, v V) bool > 检查 v 是否被包含在 slices 的每一项元素中 > - 当 v 被包含在 slices 的每一项元素中时,返回 true @@ -1111,7 +1112,7 @@ func TestInAllComparableSlices(t *testing.T) { *** -#### func AnyInAllSlices(slices []S, values []V, handler ComparisonHandler[V]) bool +#### func AnyInAllSlices\[S ~[]V, V any\](slices []S, values []V, handler ComparisonHandler[V]) bool > 检查 slices 中的每一个元素是否均包含至少任意一个 values 中的元素,当 handler 返回 true 时,表示 value 中的某个元素和 slices 中的某个元素相匹配 > - 当 slices 中的每一个元素均包含至少任意一个 values 中的元素时,返回 true @@ -1160,7 +1161,7 @@ func TestAnyInAllSlices(t *testing.T) { *** -#### func AnyInAllComparableSlices(slices []S, values []V) bool +#### func AnyInAllComparableSlices\[S ~[]V, V comparable\](slices []S, values []V) bool > 检查 slices 中的每一个元素是否均包含至少任意一个 values 中的元素 > - 当 slices 中的每一个元素均包含至少任意一个 values 中的元素时,返回 true @@ -1205,7 +1206,7 @@ func TestAnyInAllComparableSlices(t *testing.T) { *** -#### func KeyInMap(m M, key K) bool +#### func KeyInMap\[M ~map[K]V, K comparable, V any\](m M, key K) bool > 检查 m 中是否包含特定 key @@ -1249,7 +1250,7 @@ func TestKeyInMap(t *testing.T) { *** -#### func ValueInMap(m M, value V, handler ComparisonHandler[V]) bool +#### func ValueInMap\[M ~map[K]V, K comparable, V any\](m M, value V, handler ComparisonHandler[V]) bool > 检查 m 中是否包含特定 value,当 handler 返回 true 时,表示 value 和 m 中的某个元素相匹配 @@ -1296,7 +1297,7 @@ func TestValueInMap(t *testing.T) { *** -#### func AllKeyInMap(m M, keys ...K) bool +#### func AllKeyInMap\[M ~map[K]V, K comparable, V any\](m M, keys ...K) bool > 检查 m 中是否包含 keys 中所有的元素 @@ -1340,7 +1341,7 @@ func TestAllKeyInMap(t *testing.T) { *** -#### func AllValueInMap(m M, values []V, handler ComparisonHandler[V]) bool +#### func AllValueInMap\[M ~map[K]V, K comparable, V any\](m M, values []V, handler ComparisonHandler[V]) bool > 检查 m 中是否包含 values 中所有的元素,当 handler 返回 true 时,表示 values 中的某个元素和 m 中的某个元素相匹配 @@ -1386,7 +1387,7 @@ func TestAllValueInMap(t *testing.T) { *** -#### func AnyKeyInMap(m M, keys ...K) bool +#### func AnyKeyInMap\[M ~map[K]V, K comparable, V any\](m M, keys ...K) bool > 检查 m 中是否包含 keys 中任意一个元素 @@ -1430,7 +1431,7 @@ func TestAnyKeyInMap(t *testing.T) { *** -#### func AnyValueInMap(m M, values []V, handler ComparisonHandler[V]) bool +#### func AnyValueInMap\[M ~map[K]V, K comparable, V any\](m M, values []V, handler ComparisonHandler[V]) bool > 检查 m 中是否包含 values 中任意一个元素,当 handler 返回 true 时,表示 values 中的某个元素和 m 中的某个元素相匹配 @@ -1476,7 +1477,7 @@ func TestAnyValueInMap(t *testing.T) { *** -#### func AllKeyInMaps(maps []M, keys ...K) bool +#### func AllKeyInMaps\[M ~map[K]V, K comparable, V any\](maps []M, keys ...K) bool > 检查 maps 中的每一个元素是否均包含 keys 中所有的元素 @@ -1520,7 +1521,7 @@ func TestAllKeyInMaps(t *testing.T) { *** -#### func AllValueInMaps(maps []M, values []V, handler ComparisonHandler[V]) bool +#### func AllValueInMaps\[M ~map[K]V, K comparable, V any\](maps []M, values []V, handler ComparisonHandler[V]) bool > 检查 maps 中的每一个元素是否均包含 value 中所有的元素,当 handler 返回 true 时,表示 value 中的某个元素和 maps 中的某个元素相匹配 @@ -1566,7 +1567,7 @@ func TestAllValueInMaps(t *testing.T) { *** -#### func AnyKeyInMaps(maps []M, keys ...K) bool +#### func AnyKeyInMaps\[M ~map[K]V, K comparable, V any\](maps []M, keys ...K) bool > 检查 keys 中的任意一个元素是否被包含在 maps 中的任意一个元素中 > - 当 keys 中的任意一个元素被包含在 maps 中的任意一个元素中时,返回 true @@ -1611,7 +1612,7 @@ func TestAnyKeyInMaps(t *testing.T) { *** -#### func AnyValueInMaps(maps []M, values []V, handler ComparisonHandler[V]) bool +#### func AnyValueInMaps\[M ~map[K]V, K comparable, V any\](maps []M, values []V, handler ComparisonHandler[V]) bool > 检查 maps 中的任意一个元素是否包含 value 中的任意一个元素,当 handler 返回 true 时,表示 value 中的某个元素和 maps 中的某个元素相匹配 > - 当 maps 中的任意一个元素包含 value 中的任意一个元素时,返回 true @@ -1658,7 +1659,7 @@ func TestAnyValueInMaps(t *testing.T) { *** -#### func KeyInAllMaps(maps []M, key K) bool +#### func KeyInAllMaps\[M ~map[K]V, K comparable, V any\](maps []M, key K) bool > 检查 key 是否被包含在 maps 的每一个元素中 @@ -1702,7 +1703,7 @@ func TestKeyInAllMaps(t *testing.T) { *** -#### func AnyKeyInAllMaps(maps []M, keys []K) bool +#### func AnyKeyInAllMaps\[M ~map[K]V, K comparable, V any\](maps []M, keys []K) bool > 检查 maps 中的每一个元素是否均包含 keys 中任意一个元素 > - 当 maps 中的每一个元素均包含 keys 中任意一个元素时,返回 true @@ -1747,7 +1748,7 @@ func TestAnyKeyInAllMaps(t *testing.T) { *** -#### func ConvertSliceToAny(s S) []any +#### func ConvertSliceToAny\[S ~[]V, V any\](s S) []any > 将切片转换为任意类型的切片 @@ -1799,7 +1800,7 @@ func TestConvertSliceToAny(t *testing.T) { *** -#### func ConvertSliceToIndexMap(s S) map[int]V +#### func ConvertSliceToIndexMap\[S ~[]V, V any\](s S) map[int]V > 将切片转换为索引为键的映射 @@ -1850,7 +1851,7 @@ func TestConvertSliceToIndexMap(t *testing.T) { *** -#### func ConvertSliceToIndexOnlyMap(s S) map[int]struct {} +#### func ConvertSliceToIndexOnlyMap\[S ~[]V, V any\](s S) map[int]struct {} > 将切片转换为索引为键的映射 @@ -1905,7 +1906,7 @@ func TestConvertSliceToIndexOnlyMap(t *testing.T) { *** -#### func ConvertSliceToMap(s S) map[V]struct {} +#### func ConvertSliceToMap\[S ~[]V, V comparable\](s S) map[V]struct {} > 将切片转换为值为键的映射 @@ -1957,7 +1958,7 @@ func TestConvertSliceToMap(t *testing.T) { *** -#### func ConvertSliceToBoolMap(s S) map[V]bool +#### func ConvertSliceToBoolMap\[S ~[]V, V comparable\](s S) map[V]bool > 将切片转换为值为键的映射 @@ -2008,7 +2009,7 @@ func TestConvertSliceToBoolMap(t *testing.T) { *** -#### func ConvertMapKeysToSlice(m M) []K +#### func ConvertMapKeysToSlice\[M ~map[K]V, K comparable, V any\](m M) []K > 将映射的键转换为切片 @@ -2064,7 +2065,7 @@ func TestConvertMapKeysToSlice(t *testing.T) { *** -#### func ConvertMapValuesToSlice(m M) []V +#### func ConvertMapValuesToSlice\[M ~map[K]V, K comparable, V any\](m M) []V > 将映射的值转换为切片 @@ -2121,7 +2122,7 @@ func TestConvertMapValuesToSlice(t *testing.T) { *** -#### func InvertMap(m M) N +#### func InvertMap\[M ~map[K]V, N map[V]K, K comparable, V comparable\](m M) N > 将映射的键和值互换 @@ -2169,7 +2170,7 @@ func TestInvertMap(t *testing.T) { *** -#### func ConvertMapValuesToBool(m M) N +#### func ConvertMapValuesToBool\[M ~map[K]V, N map[K]bool, K comparable, V any\](m M) N > 将映射的值转换为布尔值 @@ -2217,7 +2218,7 @@ func TestConvertMapValuesToBool(t *testing.T) { *** -#### func ReverseSlice(s *S) +#### func ReverseSlice\[S ~[]V, V any\](s *S) > 将切片反转 @@ -2270,7 +2271,7 @@ func TestReverseSlice(t *testing.T) { *** -#### func ClearSlice(slice *S) +#### func ClearSlice\[S ~[]V, V any\](slice *S) > 清空切片 @@ -2319,7 +2320,7 @@ func TestClearSlice(t *testing.T) { *** -#### func ClearMap(m M) +#### func ClearMap\[M ~map[K]V, K comparable, V any\](m M) > 清空 map @@ -2368,7 +2369,7 @@ func TestClearMap(t *testing.T) { *** -#### func DropSliceByIndices(slice *S, indices ...int) +#### func DropSliceByIndices\[S ~[]V, V any\](slice *S, indices ...int) > 删除切片中特定索引的元素 @@ -2418,7 +2419,7 @@ func TestDropSliceByIndices(t *testing.T) { *** -#### func DropSliceByCondition(slice *S, condition func (v V) bool) +#### func DropSliceByCondition\[S ~[]V, V any\](slice *S, condition func (v V) bool) > 删除切片中符合条件的元素 > - condition 的返回值为 true 时,将会删除该元素 @@ -2479,7 +2480,7 @@ func TestDropSliceByCondition(t *testing.T) { *** -#### func DropSliceOverlappingElements(slice *S, anotherSlice []V, comparisonHandler ComparisonHandler[V]) +#### func DropSliceOverlappingElements\[S ~[]V, V any\](slice *S, anotherSlice []V, comparisonHandler ComparisonHandler[V]) > 删除切片中与另一个切片重叠的元素 @@ -2542,7 +2543,7 @@ func TestDropSliceOverlappingElements(t *testing.T) { *** -#### func DeduplicateSliceInPlace(s *S) +#### func DeduplicateSliceInPlace\[S ~[]V, V comparable\](s *S) > 去除切片中的重复元素 @@ -2592,7 +2593,7 @@ func TestDeduplicateSliceInPlace(t *testing.T) { *** -#### func DeduplicateSlice(s S) S +#### func DeduplicateSlice\[S ~[]V, V comparable\](s S) S > 去除切片中的重复元素,返回新切片 @@ -2641,7 +2642,7 @@ func TestDeduplicateSlice(t *testing.T) { *** -#### func DeduplicateSliceInPlaceWithCompare(s *S, compare func (a V) bool) +#### func DeduplicateSliceInPlaceWithCompare\[S ~[]V, V any\](s *S, compare func (a V) bool) > 去除切片中的重复元素,使用自定义的比较函数 @@ -2695,7 +2696,7 @@ func TestDeduplicateSliceInPlaceWithCompare(t *testing.T) { *** -#### func DeduplicateSliceWithCompare(s S, compare func (a V) bool) S +#### func DeduplicateSliceWithCompare\[S ~[]V, V any\](s S, compare func (a V) bool) S > 去除切片中的重复元素,使用自定义的比较函数,返回新的切片 @@ -2748,7 +2749,7 @@ func TestDeduplicateSliceWithCompare(t *testing.T) { *** -#### func FilterOutByIndices(slice S, indices ...int) S +#### func FilterOutByIndices\[S []V, V any\](slice S, indices ...int) S > 过滤切片中特定索引的元素,返回过滤后的切片 @@ -2798,7 +2799,7 @@ func TestFilterOutByIndices(t *testing.T) { *** -#### func FilterOutByCondition(slice S, condition func (v V) bool) S +#### func FilterOutByCondition\[S ~[]V, V any\](slice S, condition func (v V) bool) S > 过滤切片中符合条件的元素,返回过滤后的切片 > - condition 的返回值为 true 时,将会过滤掉该元素 @@ -2857,7 +2858,7 @@ func TestFilterOutByCondition(t *testing.T) { *** -#### func FilterOutByKey(m M, key K) M +#### func FilterOutByKey\[M ~map[K]V, K comparable, V any\](m M, key K) M > 过滤 map 中特定的 key,返回过滤后的 map @@ -2907,7 +2908,7 @@ func TestFilterOutByKey(t *testing.T) { *** -#### func FilterOutByValue(m M, value V, handler ComparisonHandler[V]) M +#### func FilterOutByValue\[M ~map[K]V, K comparable, V any\](m M, value V, handler ComparisonHandler[V]) M > 过滤 map 中特定的 value,返回过滤后的 map @@ -2961,7 +2962,7 @@ func TestFilterOutByValue(t *testing.T) { *** -#### func FilterOutByKeys(m M, keys ...K) M +#### func FilterOutByKeys\[M ~map[K]V, K comparable, V any\](m M, keys ...K) M > 过滤 map 中多个 key,返回过滤后的 map @@ -3011,7 +3012,7 @@ func TestFilterOutByKeys(t *testing.T) { *** -#### func FilterOutByValues(m M, values []V, handler ComparisonHandler[V]) M +#### func FilterOutByValues\[M ~map[K]V, K comparable, V any\](m M, values []V, handler ComparisonHandler[V]) M > 过滤 map 中多个 values,返回过滤后的 map @@ -3067,7 +3068,7 @@ func TestFilterOutByValues(t *testing.T) { *** -#### func FilterOutByMap(m M, condition func (k K, v V) bool) M +#### func FilterOutByMap\[M ~map[K]V, K comparable, V any\](m M, condition func (k K, v V) bool) M > 过滤 map 中符合条件的元素,返回过滤后的 map > - condition 的返回值为 true 时,将会过滤掉该元素 @@ -3122,7 +3123,7 @@ func TestFilterOutByMap(t *testing.T) { *** -#### func FindLoopedNextInSlice(slice S, i int) (next int, value V) +#### func FindLoopedNextInSlice\[S ~[]V, V any\](slice S, i int) (next int, value V) > 返回 i 的下一个数组成员,当 i 达到数组长度时从 0 开始 > - 当 i 为负数时将返回第一个元素 @@ -3167,7 +3168,7 @@ func TestFindLoopedNextInSlice(t *testing.T) { *** -#### func FindLoopedPrevInSlice(slice S, i int) (prev int, value V) +#### func FindLoopedPrevInSlice\[S ~[]V, V any\](slice S, i int) (prev int, value V) > 返回 i 的上一个数组成员,当 i 为 0 时从数组末尾开始 > - 当 i 为负数时将返回最后一个元素 @@ -3212,7 +3213,7 @@ func TestFindLoopedPrevInSlice(t *testing.T) { *** -#### func FindCombinationsInSliceByRange(s S, minSize int, maxSize int) []S +#### func FindCombinationsInSliceByRange\[S ~[]V, V any\](s S, minSize int, maxSize int) []S > 获取给定数组的所有组合,且每个组合的成员数量限制在指定范围内 @@ -3257,7 +3258,7 @@ func TestFindCombinationsInSliceByRange(t *testing.T) { *** -#### func FindFirstOrDefaultInSlice(slice S, defaultValue V) V +#### func FindFirstOrDefaultInSlice\[S ~[]V, V any\](slice S, defaultValue V) V > 判断切片中是否存在元素,返回第一个元素,不存在则返回默认值 @@ -3300,7 +3301,7 @@ func TestFindFirstOrDefaultInSlice(t *testing.T) { *** -#### func FindOrDefaultInSlice(slice S, defaultValue V, handler func (v V) bool) (t V) +#### func FindOrDefaultInSlice\[S ~[]V, V any\](slice S, defaultValue V, handler func (v V) bool) (t V) > 判断切片中是否存在某个元素,返回第一个匹配的索引和元素,不存在则返回默认值 @@ -3347,7 +3348,7 @@ func TestFindOrDefaultInSlice(t *testing.T) { *** -#### func FindOrDefaultInComparableSlice(slice S, v V, defaultValue V) (t V) +#### func FindOrDefaultInComparableSlice\[S ~[]V, V comparable\](slice S, v V, defaultValue V) (t V) > 判断切片中是否存在某个元素,返回第一个匹配的索引和元素,不存在则返回默认值 @@ -3390,7 +3391,7 @@ func TestFindOrDefaultInComparableSlice(t *testing.T) { *** -#### func FindInSlice(slice S, handler func (v V) bool) (i int, t V) +#### func FindInSlice\[S ~[]V, V any\](slice S, handler func (v V) bool) (i int, t V) > 判断切片中是否存在某个元素,返回第一个匹配的索引和元素,不存在则索引返回 -1 @@ -3437,7 +3438,7 @@ func TestFindInSlice(t *testing.T) { *** -#### func FindIndexInSlice(slice S, handler func (v V) bool) int +#### func FindIndexInSlice\[S ~[]V, V any\](slice S, handler func (v V) bool) int > 判断切片中是否存在某个元素,返回第一个匹配的索引,不存在则索引返回 -1 @@ -3484,7 +3485,7 @@ func TestFindIndexInSlice(t *testing.T) { *** -#### func FindInComparableSlice(slice S, v V) (i int, t V) +#### func FindInComparableSlice\[S ~[]V, V comparable\](slice S, v V) (i int, t V) > 判断切片中是否存在某个元素,返回第一个匹配的索引和元素,不存在则索引返回 -1 @@ -3527,7 +3528,7 @@ func TestFindInComparableSlice(t *testing.T) { *** -#### func FindIndexInComparableSlice(slice S, v V) int +#### func FindIndexInComparableSlice\[S ~[]V, V comparable\](slice S, v V) int > 判断切片中是否存在某个元素,返回第一个匹配的索引,不存在则索引返回 -1 @@ -3570,7 +3571,7 @@ func TestFindIndexInComparableSlice(t *testing.T) { *** -#### func FindMinimumInComparableSlice(slice S) (result V) +#### func FindMinimumInComparableSlice\[S ~[]V, V generic.Ordered\](slice S) (result V) > 获取切片中的最小值 @@ -3613,7 +3614,7 @@ func TestFindMinimumInComparableSlice(t *testing.T) { *** -#### func FindMinimumInSlice(slice S, handler OrderedValueGetter[V, N]) (result V) +#### func FindMinimumInSlice\[S ~[]V, V any, N generic.Ordered\](slice S, handler OrderedValueGetter[V, N]) (result V) > 获取切片中的最小值 @@ -3660,7 +3661,7 @@ func TestFindMinimumInSlice(t *testing.T) { *** -#### func FindMaximumInComparableSlice(slice S) (result V) +#### func FindMaximumInComparableSlice\[S ~[]V, V generic.Ordered\](slice S) (result V) > 获取切片中的最大值 @@ -3703,7 +3704,7 @@ func TestFindMaximumInComparableSlice(t *testing.T) { *** -#### func FindMaximumInSlice(slice S, handler OrderedValueGetter[V, N]) (result V) +#### func FindMaximumInSlice\[S ~[]V, V any, N generic.Ordered\](slice S, handler OrderedValueGetter[V, N]) (result V) > 获取切片中的最大值 @@ -3750,7 +3751,7 @@ func TestFindMaximumInSlice(t *testing.T) { *** -#### func FindMin2MaxInComparableSlice(slice S) (min V, max V) +#### func FindMin2MaxInComparableSlice\[S ~[]V, V generic.Ordered\](slice S) (min V, max V) > 获取切片中的最小值和最大值 @@ -3794,7 +3795,7 @@ func TestFindMin2MaxInComparableSlice(t *testing.T) { *** -#### func FindMin2MaxInSlice(slice S, handler OrderedValueGetter[V, N]) (min V, max V) +#### func FindMin2MaxInSlice\[S ~[]V, V any, N generic.Ordered\](slice S, handler OrderedValueGetter[V, N]) (min V, max V) > 获取切片中的最小值和最大值 @@ -3842,7 +3843,7 @@ func TestFindMin2MaxInSlice(t *testing.T) { *** -#### func FindMinFromComparableMap(m M) (result V) +#### func FindMinFromComparableMap\[M ~map[K]V, K comparable, V generic.Ordered\](m M) (result V) > 获取 map 中的最小值 @@ -3885,7 +3886,7 @@ func TestFindMinFromComparableMap(t *testing.T) { *** -#### func FindMinFromMap(m M, handler OrderedValueGetter[V, N]) (result V) +#### func FindMinFromMap\[M ~map[K]V, K comparable, V any, N generic.Ordered\](m M, handler OrderedValueGetter[V, N]) (result V) > 获取 map 中的最小值 @@ -3932,7 +3933,7 @@ func TestFindMinFromMap(t *testing.T) { *** -#### func FindMaxFromComparableMap(m M) (result V) +#### func FindMaxFromComparableMap\[M ~map[K]V, K comparable, V generic.Ordered\](m M) (result V) > 获取 map 中的最大值 @@ -3975,7 +3976,7 @@ func TestFindMaxFromComparableMap(t *testing.T) { *** -#### func FindMaxFromMap(m M, handler OrderedValueGetter[V, N]) (result V) +#### func FindMaxFromMap\[M ~map[K]V, K comparable, V any, N generic.Ordered\](m M, handler OrderedValueGetter[V, N]) (result V) > 获取 map 中的最大值 @@ -4022,7 +4023,7 @@ func TestFindMaxFromMap(t *testing.T) { *** -#### func FindMin2MaxFromComparableMap(m M) (min V, max V) +#### func FindMin2MaxFromComparableMap\[M ~map[K]V, K comparable, V generic.Ordered\](m M) (min V, max V) > 获取 map 中的最小值和最大值 @@ -4066,7 +4067,7 @@ func TestFindMin2MaxFromComparableMap(t *testing.T) { *** -#### func FindMin2MaxFromMap(m M) (min V, max V) +#### func FindMin2MaxFromMap\[M ~map[K]V, K comparable, V generic.Ordered\](m M) (min V, max V) > 获取 map 中的最小值和最大值 @@ -4110,7 +4111,7 @@ func TestFindMin2MaxFromMap(t *testing.T) { *** -#### func SwapSlice(slice *S, i int, j int) +#### func SwapSlice\[S ~[]V, V any\](slice *S, i int, j int) > 将切片中的两个元素进行交换 @@ -4158,7 +4159,7 @@ func TestSwapSlice(t *testing.T) { *** -#### func MappingFromSlice(slice S, handler func (value V) N) NS +#### func MappingFromSlice\[S ~[]V, NS []N, V any, N any\](slice S, handler func (value V) N) NS > 将切片中的元素进行转换 @@ -4210,7 +4211,7 @@ func TestMappingFromSlice(t *testing.T) { *** -#### func MappingFromMap(m M, handler func (value V) N) NM +#### func MappingFromMap\[M ~map[K]V, NM map[K]N, K comparable, V any, N any\](m M, handler func (value V) N) NM > 将 map 中的元素进行转换 @@ -4262,7 +4263,7 @@ func TestMappingFromMap(t *testing.T) { *** -#### func MergeSlices(slices ...S) (result S) +#### func MergeSlices\[S ~[]V, V any\](slices ...S) (result S) > 合并切片 @@ -4309,7 +4310,7 @@ func TestMergeSlices(t *testing.T) { *** -#### func MergeMaps(maps ...M) (result M) +#### func MergeMaps\[M ~map[K]V, K comparable, V any\](maps ...M) (result M) > 合并 map,当多个 map 中存在相同的 key 时,后面的 map 中的 key 将会覆盖前面的 map 中的 key @@ -4352,7 +4353,7 @@ func TestMergeMaps(t *testing.T) { *** -#### func MergeMapsWithSkip(maps ...M) (result M) +#### func MergeMapsWithSkip\[M ~map[K]V, K comparable, V any\](maps ...M) (result M) > 合并 map,当多个 map 中存在相同的 key 时,后面的 map 中的 key 将会被跳过 @@ -4395,7 +4396,7 @@ func TestMergeMapsWithSkip(t *testing.T) { *** -#### func ChooseRandomSliceElementRepeatN(slice S, n int) (result []V) +#### func ChooseRandomSliceElementRepeatN\[S ~[]V, V any\](slice S, n int) (result []V) > 返回 slice 中的 n 个可重复随机元素 > - 当 slice 长度为 0 或 n 小于等于 0 时将会返回 nil @@ -4439,7 +4440,7 @@ func TestChooseRandomSliceElementRepeatN(t *testing.T) { *** -#### func ChooseRandomIndexRepeatN(slice S, n int) (result []int) +#### func ChooseRandomIndexRepeatN\[S ~[]V, V any\](slice S, n int) (result []int) > 返回 slice 中的 n 个可重复随机元素的索引 > - 当 slice 长度为 0 或 n 小于等于 0 时将会返回 nil @@ -4483,7 +4484,7 @@ func TestChooseRandomIndexRepeatN(t *testing.T) { *** -#### func ChooseRandomSliceElement(slice S) (v V) +#### func ChooseRandomSliceElement\[S ~[]V, V any\](slice S) (v V) > 返回 slice 中随机一个元素,当 slice 长度为 0 时将会得到 V 的零值 @@ -4526,7 +4527,7 @@ func TestChooseRandomSliceElement(t *testing.T) { *** -#### func ChooseRandomIndex(slice S) (index int) +#### func ChooseRandomIndex\[S ~[]V, V any\](slice S) (index int) > 返回 slice 中随机一个元素的索引,当 slice 长度为 0 时将会得到 -1 @@ -4569,7 +4570,7 @@ func TestChooseRandomIndex(t *testing.T) { *** -#### func ChooseRandomSliceElementN(slice S, n int) (result []V) +#### func ChooseRandomSliceElementN\[S ~[]V, V any\](slice S, n int) (result []V) > 返回 slice 中的 n 个不可重复的随机元素 > - 当 slice 长度为 0 或 n 大于 slice 长度或小于 0 时将会发生 panic @@ -4612,7 +4613,7 @@ func TestChooseRandomSliceElementN(t *testing.T) { *** -#### func ChooseRandomIndexN(slice S, n int) (result []int) +#### func ChooseRandomIndexN\[S ~[]V, V any\](slice S, n int) (result []int) > 获取切片中的 n 个随机元素的索引 > - 如果 n 大于切片长度或小于 0 时将会发生 panic @@ -4656,7 +4657,7 @@ func TestChooseRandomIndexN(t *testing.T) { *** -#### func ChooseRandomMapKeyRepeatN(m M, n int) (result []K) +#### func ChooseRandomMapKeyRepeatN\[M ~map[K]V, K comparable, V any\](m M, n int) (result []K) > 获取 map 中的 n 个随机 key,允许重复 > - 如果 n 大于 map 长度或小于 0 时将会发生 panic @@ -4700,7 +4701,7 @@ func TestChooseRandomMapKeyRepeatN(t *testing.T) { *** -#### func ChooseRandomMapValueRepeatN(m M, n int) (result []V) +#### func ChooseRandomMapValueRepeatN\[M ~map[K]V, K comparable, V any\](m M, n int) (result []V) > 获取 map 中的 n 个随机 n,允许重复 > - 如果 n 大于 map 长度或小于 0 时将会发生 panic @@ -4744,7 +4745,7 @@ func TestChooseRandomMapValueRepeatN(t *testing.T) { *** -#### func ChooseRandomMapKeyAndValueRepeatN(m M, n int) M +#### func ChooseRandomMapKeyAndValueRepeatN\[M ~map[K]V, K comparable, V any\](m M, n int) M > 获取 map 中的 n 个随机 key 和 v,允许重复 > - 如果 n 大于 map 长度或小于 0 时将会发生 panic @@ -4788,7 +4789,7 @@ func TestChooseRandomMapKeyAndValueRepeatN(t *testing.T) { *** -#### func ChooseRandomMapKey(m M) (k K) +#### func ChooseRandomMapKey\[M ~map[K]V, K comparable, V any\](m M) (k K) > 获取 map 中的随机 key @@ -4831,7 +4832,7 @@ func TestChooseRandomMapKey(t *testing.T) { *** -#### func ChooseRandomMapValue(m M) (v V) +#### func ChooseRandomMapValue\[M ~map[K]V, K comparable, V any\](m M) (v V) > 获取 map 中的随机 value @@ -4874,7 +4875,7 @@ func TestChooseRandomMapValue(t *testing.T) { *** -#### func ChooseRandomMapKeyN(m M, n int) (result []K) +#### func ChooseRandomMapKeyN\[M ~map[K]V, K comparable, V any\](m M, n int) (result []K) > 获取 map 中的 inputN 个随机 key > - 如果 inputN 大于 map 长度或小于 0 时将会发生 panic @@ -4890,7 +4891,7 @@ func ExampleChooseRandomMapKeyN() { ``` *** -#### func ChooseRandomMapValueN(m M, n int) (result []V) +#### func ChooseRandomMapValueN\[M ~map[K]V, K comparable, V any\](m M, n int) (result []V) > 获取 map 中的 n 个随机 value > - 如果 n 大于 map 长度或小于 0 时将会发生 panic @@ -4934,7 +4935,7 @@ func TestChooseRandomMapValueN(t *testing.T) { *** -#### func ChooseRandomMapKeyAndValue(m M) (k K, v V) +#### func ChooseRandomMapKeyAndValue\[M ~map[K]V, K comparable, V any\](m M) (k K, v V) > 获取 map 中的随机 key 和 v @@ -4977,7 +4978,7 @@ func TestChooseRandomMapKeyAndValue(t *testing.T) { *** -#### func ChooseRandomMapKeyAndValueN(m M, n int) M +#### func ChooseRandomMapKeyAndValueN\[M ~map[K]V, K comparable, V any\](m M, n int) M > 获取 map 中的 inputN 个随机 key 和 v > - 如果 n 大于 map 长度或小于 0 时将会发生 panic @@ -5023,7 +5024,7 @@ func TestChooseRandomMapKeyAndValueN(t *testing.T) { *** -#### func DescBy(a Sort, b Sort) bool +#### func DescBy\[Sort generic.Ordered\](a Sort, b Sort) bool > 返回降序比较结果 @@ -5073,7 +5074,7 @@ func TestDescBy(t *testing.T) { *** -#### func AscBy(a Sort, b Sort) bool +#### func AscBy\[Sort generic.Ordered\](a Sort, b Sort) bool > 返回升序比较结果 @@ -5123,7 +5124,7 @@ func TestAscBy(t *testing.T) { *** -#### func Desc(slice *S, getter func (index int) Sort) +#### func Desc\[S ~[]V, V any, Sort generic.Ordered\](slice *S, getter func (index int) Sort) > 对切片进行降序排序 @@ -5173,7 +5174,7 @@ func TestDesc(t *testing.T) { *** -#### func DescByClone(slice S, getter func (index int) Sort) S +#### func DescByClone\[S ~[]V, V any, Sort generic.Ordered\](slice S, getter func (index int) Sort) S > 对切片进行降序排序,返回排序后的切片 @@ -5223,7 +5224,7 @@ func TestDescByClone(t *testing.T) { *** -#### func Asc(slice *S, getter func (index int) Sort) +#### func Asc\[S ~[]V, V any, Sort generic.Ordered\](slice *S, getter func (index int) Sort) > 对切片进行升序排序 @@ -5273,7 +5274,7 @@ func TestAsc(t *testing.T) { *** -#### func AscByClone(slice S, getter func (index int) Sort) S +#### func AscByClone\[S ~[]V, V any, Sort generic.Ordered\](slice S, getter func (index int) Sort) S > 对切片进行升序排序,返回排序后的切片 @@ -5323,7 +5324,7 @@ func TestAscByClone(t *testing.T) { *** -#### func Shuffle(slice *S) +#### func Shuffle\[S ~[]V, V any\](slice *S) > 对切片进行随机排序 @@ -5367,7 +5368,7 @@ func TestShuffle(t *testing.T) { *** -#### func ShuffleByClone(slice S) S +#### func ShuffleByClone\[S ~[]V, V any\](slice S) S > 对切片进行随机排序,返回排序后的切片 diff --git a/utils/collection/clone.go b/utils/collection/clone.go index 69a7c0d..44400ce 100644 --- a/utils/collection/clone.go +++ b/utils/collection/clone.go @@ -4,12 +4,13 @@ import ( "slices" ) -// CloneSlice 克隆切片,该函数是 slices.Clone 的快捷方式 +// CloneSlice 通过创建一个新切片并将 slice 的元素复制到新切片的方式来克隆切片 func CloneSlice[S ~[]V, V any](slice S) S { return slices.Clone(slice) } -// CloneMap 克隆 map +// CloneMap 通过创建一个新 map 并将 m 的元素复制到新 map 的方式来克隆 map +// - 当 m 为空时,将会返回 nil func CloneMap[M ~map[K]V, K comparable, V any](m M) M { if m == nil { return nil diff --git a/utils/collection/doc.go b/utils/collection/doc.go index 50528d9..195bdbb 100644 --- a/utils/collection/doc.go +++ b/utils/collection/doc.go @@ -1,2 +1,2 @@ -// Package collection 用于对 input 和 map 操作的工具函数 +// Package collection 定义了各种对于集合操作有用的各种函数 package collection diff --git a/utils/collection/listings/README.md b/utils/collection/listings/README.md index 9179267..6d0a0dd 100644 --- a/utils/collection/listings/README.md +++ b/utils/collection/listings/README.md @@ -36,22 +36,22 @@ *** ## 详情信息 -#### func NewMatrix(dimensions ...int) *Matrix[V] +#### func NewMatrix\[V any\](dimensions ...int) *Matrix[V] > 创建一个新的 Matrix 实例。 *** -#### func NewPagedSlice(pageSize int) *PagedSlice[T] +#### func NewPagedSlice\[T any\](pageSize int) *PagedSlice[T] > 创建一个新的 PagedSlice 实例。 *** -#### func NewPrioritySlice(lengthAndCap ...int) *PrioritySlice[V] +#### func NewPrioritySlice\[V any\](lengthAndCap ...int) *PrioritySlice[V] > 创建一个优先级切片 *** -#### func NewSyncSlice(length int, cap int) *SyncSlice[V] +#### func NewSyncSlice\[V any\](length int, cap int) *SyncSlice[V] > 创建一个 SyncSlice diff --git a/utils/collection/mappings/README.md b/utils/collection/mappings/README.md index 270393b..b91ebf6 100644 --- a/utils/collection/mappings/README.md +++ b/utils/collection/mappings/README.md @@ -30,7 +30,7 @@ *** ## 详情信息 -#### func NewSyncMap(source ...map[K]V) *SyncMap[K, V] +#### func NewSyncMap\[K comparable, V any\](source ...map[K]V) *SyncMap[K, V] > 创建一个 SyncMap diff --git a/utils/combination/README.md b/utils/combination/README.md index bbe8837..089fb4d 100644 --- a/utils/combination/README.md +++ b/utils/combination/README.md @@ -65,12 +65,12 @@ combination 包提供了一些实用的组合函数。 *** ## 详情信息 -#### func NewCombination(options ...Option[T]) *Combination[T] +#### func NewCombination\[T Item\](options ...Option[T]) *Combination[T] > 创建一个新的组合器 *** -#### func WithEvaluation(evaluate func (items []T) float64) Option[T] +#### func WithEvaluation\[T Item\](evaluate func (items []T) float64) Option[T] > 设置组合评估函数 > - 用于对组合进行评估,返回一个分值的评价函数 @@ -79,57 +79,57 @@ combination 包提供了一些实用的组合函数。 > - 默认的评估函数将返回一个随机数 *** -#### func NewMatcher(options ...MatcherOption[T]) *Matcher[T] +#### func NewMatcher\[T Item\](options ...MatcherOption[T]) *Matcher[T] > 创建一个新的匹配器 *** -#### func WithMatcherEvaluation(evaluate func (items []T) float64) MatcherOption[T] +#### func WithMatcherEvaluation\[T Item\](evaluate func (items []T) float64) MatcherOption[T] > 设置匹配器评估函数 > - 用于对组合进行评估,返回一个分值的评价函数 > - 通过该选项将覆盖匹配器的默认(WithEvaluation)评估函数 *** -#### func WithMatcherLeastLength(length int) MatcherOption[T] +#### func WithMatcherLeastLength\[T Item\](length int) MatcherOption[T] > 通过匹配最小长度的组合创建匹配器 > - length: 组合的长度,表示需要匹配的组合最小数量 *** -#### func WithMatcherLength(length int) MatcherOption[T] +#### func WithMatcherLength\[T Item\](length int) MatcherOption[T] > 通过匹配长度的组合创建匹配器 > - length: 组合的长度,表示需要匹配的组合数量 *** -#### func WithMatcherMostLength(length int) MatcherOption[T] +#### func WithMatcherMostLength\[T Item\](length int) MatcherOption[T] > 通过匹配最大长度的组合创建匹配器 > - length: 组合的长度,表示需要匹配的组合最大数量 *** -#### func WithMatcherIntervalLength(min int, max int) MatcherOption[T] +#### func WithMatcherIntervalLength\[T Item\](min int, max int) MatcherOption[T] > 通过匹配长度区间的组合创建匹配器 > - min: 组合的最小长度,表示需要匹配的组合最小数量 > - max: 组合的最大长度,表示需要匹配的组合最大数量 *** -#### func WithMatcherContinuity(getIndex func (item T) Index) MatcherOption[T] +#### func WithMatcherContinuity\[T Item, Index generic.Number\](getIndex func (item T) Index) MatcherOption[T] > 通过匹配连续的组合创建匹配器 > - index: 用于获取组合中元素的索引值,用于判断是否连续 *** -#### func WithMatcherSame(count int, getType func (item T) E) MatcherOption[T] +#### func WithMatcherSame\[T Item, E generic.Ordered\](count int, getType func (item T) E) MatcherOption[T] > 通过匹配相同的组合创建匹配器 > - count: 组合中相同元素的数量,当 count <= 0 时,表示相同元素的数量不限 > - getType: 用于获取组合中元素的类型,用于判断是否相同 *** -#### func WithMatcherNCarryM(n int, m int, getType func (item T) E) MatcherOption[T] +#### func WithMatcherNCarryM\[T Item, E generic.Ordered\](n int, m int, getType func (item T) E) MatcherOption[T] > 通过匹配 N 携带 M 的组合创建匹配器 > - n: 组合中元素的数量,表示需要匹配的组合数量,n 的类型需要全部相同 @@ -137,7 +137,7 @@ combination 包提供了一些实用的组合函数。 > - getType: 用于获取组合中元素的类型,用于判断是否相同 *** -#### func WithMatcherNCarryIndependentM(n int, m int, getType func (item T) E) MatcherOption[T] +#### func WithMatcherNCarryIndependentM\[T Item, E generic.Ordered\](n int, m int, getType func (item T) E) MatcherOption[T] > 通过匹配 N 携带独立 M 的组合创建匹配器 > - n: 组合中元素的数量,表示需要匹配的组合数量,n 的类型需要全部相同 @@ -145,87 +145,87 @@ combination 包提供了一些实用的组合函数。 > - getType: 用于获取组合中元素的类型,用于判断是否相同 *** -#### func NewValidator(options ...ValidatorOption[T]) *Validator[T] +#### func NewValidator\[T Item\](options ...ValidatorOption[T]) *Validator[T] > 创建一个新的校验器 *** -#### func WithValidatorHandle(handle func (items []T) bool) ValidatorOption[T] +#### func WithValidatorHandle\[T Item\](handle func (items []T) bool) ValidatorOption[T] > 通过特定的验证函数对组合进行验证 *** -#### func WithValidatorHandleLength(length int) ValidatorOption[T] +#### func WithValidatorHandleLength\[T Item\](length int) ValidatorOption[T] > 校验组合的长度是否符合要求 *** -#### func WithValidatorHandleLengthRange(min int, max int) ValidatorOption[T] +#### func WithValidatorHandleLengthRange\[T Item\](min int, max int) ValidatorOption[T] > 校验组合的长度是否在指定的范围内 *** -#### func WithValidatorHandleLengthMin(min int) ValidatorOption[T] +#### func WithValidatorHandleLengthMin\[T Item\](min int) ValidatorOption[T] > 校验组合的长度是否大于等于指定的最小值 *** -#### func WithValidatorHandleLengthMax(max int) ValidatorOption[T] +#### func WithValidatorHandleLengthMax\[T Item\](max int) ValidatorOption[T] > 校验组合的长度是否小于等于指定的最大值 *** -#### func WithValidatorHandleLengthNot(length int) ValidatorOption[T] +#### func WithValidatorHandleLengthNot\[T Item\](length int) ValidatorOption[T] > 校验组合的长度是否不等于指定的值 *** -#### func WithValidatorHandleTypeLength(length int, getType func (item T) E) ValidatorOption[T] +#### func WithValidatorHandleTypeLength\[T Item, E generic.Ordered\](length int, getType func (item T) E) ValidatorOption[T] > 校验组合成员类型数量是否为指定的值 *** -#### func WithValidatorHandleTypeLengthRange(min int, max int, getType func (item T) E) ValidatorOption[T] +#### func WithValidatorHandleTypeLengthRange\[T Item, E generic.Ordered\](min int, max int, getType func (item T) E) ValidatorOption[T] > 校验组合成员类型数量是否在指定的范围内 *** -#### func WithValidatorHandleTypeLengthMin(min int, getType func (item T) E) ValidatorOption[T] +#### func WithValidatorHandleTypeLengthMin\[T Item, E generic.Ordered\](min int, getType func (item T) E) ValidatorOption[T] > 校验组合成员类型数量是否大于等于指定的最小值 *** -#### func WithValidatorHandleTypeLengthMax(max int, getType func (item T) E) ValidatorOption[T] +#### func WithValidatorHandleTypeLengthMax\[T Item, E generic.Ordered\](max int, getType func (item T) E) ValidatorOption[T] > 校验组合成员类型数量是否小于等于指定的最大值 *** -#### func WithValidatorHandleTypeLengthNot(length int, getType func (item T) E) ValidatorOption[T] +#### func WithValidatorHandleTypeLengthNot\[T Item, E generic.Ordered\](length int, getType func (item T) E) ValidatorOption[T] > 校验组合成员类型数量是否不等于指定的值 *** -#### func WithValidatorHandleContinuous(getIndex func (item T) Index) ValidatorOption[T] +#### func WithValidatorHandleContinuous\[T Item, Index generic.Integer\](getIndex func (item T) Index) ValidatorOption[T] > 校验组合成员是否连续 *** -#### func WithValidatorHandleContinuousNot(getIndex func (item T) Index) ValidatorOption[T] +#### func WithValidatorHandleContinuousNot\[T Item, Index generic.Integer\](getIndex func (item T) Index) ValidatorOption[T] > 校验组合成员是否不连续 *** -#### func WithValidatorHandleGroupContinuous(getType func (item T) E, getIndex func (item T) Index) ValidatorOption[T] +#### func WithValidatorHandleGroupContinuous\[T Item, E generic.Ordered, Index generic.Integer\](getType func (item T) E, getIndex func (item T) Index) ValidatorOption[T] > 校验组合成员是否能够按类型分组并且连续 *** -#### func WithValidatorHandleGroupContinuousN(n int, getType func (item T) E, getIndex func (item T) Index) ValidatorOption[T] +#### func WithValidatorHandleGroupContinuousN\[T Item, E generic.Ordered, Index generic.Integer\](n int, getType func (item T) E, getIndex func (item T) Index) ValidatorOption[T] > 校验组合成员是否能够按分组为 n 组类型并且连续 *** -#### func WithValidatorHandleNCarryM(n int, m int, getType func (item T) E) ValidatorOption[T] +#### func WithValidatorHandleNCarryM\[T Item, E generic.Ordered\](n int, m int, getType func (item T) E) ValidatorOption[T] > 校验组合成员是否匹配 N 携带相同的 M 的组合 > - n: 组合中元素的数量,表示需要匹配的组合数量,n 的类型需要全部相同 @@ -233,7 +233,7 @@ combination 包提供了一些实用的组合函数。 > - getType: 用于获取组合中元素的类型,用于判断是否相同 *** -#### func WithValidatorHandleNCarryIndependentM(n int, m int, getType func (item T) E) ValidatorOption[T] +#### func WithValidatorHandleNCarryIndependentM\[T Item, E generic.Ordered\](n int, m int, getType func (item T) E) ValidatorOption[T] > 校验组合成员是否匹配 N 携带独立的 M 的组合 > - n: 组合中元素的数量,表示需要匹配的组合数量,n 的类型需要全部相同 diff --git a/utils/deck/README.md b/utils/deck/README.md index 3bfbca8..4dd3712 100644 --- a/utils/deck/README.md +++ b/utils/deck/README.md @@ -33,12 +33,12 @@ deck 包中的内容用于针对一堆内容的管理,适用但不限于牌堆 *** ## 详情信息 -#### func NewDeck() *Deck[I] +#### func NewDeck\[I Item\]() *Deck[I] > 创建一个新的甲板 *** -#### func NewGroup(guid int64, fillHandle func (guid int64) []I) *Group[I] +#### func NewGroup\[I Item\](guid int64, fillHandle func (guid int64) []I) *Group[I] > 创建一个新的组 diff --git a/utils/fsm/README.md b/utils/fsm/README.md index 330019f..a8c0f02 100644 --- a/utils/fsm/README.md +++ b/utils/fsm/README.md @@ -36,34 +36,34 @@ *** ## 详情信息 -#### func NewFSM(data Data) *FSM[State, Data] +#### func NewFSM\[State comparable, Data any\](data Data) *FSM[State, Data] > 创建一个新的状态机 *** -#### func WithEnterBeforeEvent(fn func (state *FSM[State, Data])) Option[State, Data] +#### func WithEnterBeforeEvent\[State comparable, Data any\](fn func (state *FSM[State, Data])) Option[State, Data] > 设置状态进入前的回调 > - 在首次设置状态时,状态机本身的当前状态为零值状态 *** -#### func WithEnterAfterEvent(fn func (state *FSM[State, Data])) Option[State, Data] +#### func WithEnterAfterEvent\[State comparable, Data any\](fn func (state *FSM[State, Data])) Option[State, Data] > 设置状态进入后的回调 *** -#### func WithUpdateEvent(fn func (state *FSM[State, Data])) Option[State, Data] +#### func WithUpdateEvent\[State comparable, Data any\](fn func (state *FSM[State, Data])) Option[State, Data] > 设置状态内刷新的回调 *** -#### func WithExitBeforeEvent(fn func (state *FSM[State, Data])) Option[State, Data] +#### func WithExitBeforeEvent\[State comparable, Data any\](fn func (state *FSM[State, Data])) Option[State, Data] > 设置状态退出前的回调 > - 该阶段状态机的状态为退出前的状态,而非新的状态 *** -#### func WithExitAfterEvent(fn func (state *FSM[State, Data])) Option[State, Data] +#### func WithExitAfterEvent\[State comparable, Data any\](fn func (state *FSM[State, Data])) Option[State, Data] > 设置状态退出后的回调 > - 该阶段状态机的状态为新的状态,而非退出前的状态 diff --git a/utils/generator/genreadme/builder.go b/utils/generator/genreadme/builder.go index e4ea42b..c2061c2 100644 --- a/utils/generator/genreadme/builder.go +++ b/utils/generator/genreadme/builder.go @@ -154,8 +154,21 @@ func (b *Builder) genStructs() { continue } titleBuild() - b.title(4, strings.TrimSpace(fmt.Sprintf("func %s%s %s", + b.title(4, strings.TrimSpace(fmt.Sprintf("func %s%s%s %s", function.Name, + func() string { + var sb strings.Builder + if len(function.Generic) > 0 { + sb.WriteString("\\[") + var genericStr = make([]string, 0) + for _, field := range function.Generic { + genericStr = append(genericStr, fmt.Sprintf("%s %s", field.Name, field.Type.Sign)) + } + sb.WriteString(strings.Join(genericStr, ", ")) + sb.WriteString("\\]") + } + return sb.String() + }(), func() string { f := funcHandler(function.Params) if !strings.HasPrefix(f, "(") { @@ -279,9 +292,6 @@ func (b *Builder) genStructs() { for _, comment := range function.Comments.Clear { b.quote(comment) } - if function.Name == "Write" { - fmt.Println() - } if example := b.p.GetExampleTest(function); example != nil { b.newLine("示例代码:", "```go\n", example.Code(), "```\n") } diff --git a/utils/generic/README.md b/utils/generic/README.md index b4deb86..9894f69 100644 --- a/utils/generic/README.md +++ b/utils/generic/README.md @@ -48,17 +48,17 @@ generic 目的在于提供一组基于泛型的用于处理通用功能的函数 *** ## 详情信息 -#### func IsNil(v V) bool +#### func IsNil\[V any\](v V) bool > 检查指定的值是否为 nil *** -#### func IsAllNil(v ...V) bool +#### func IsAllNil\[V any\](v ...V) bool > 检查指定的值是否全部为 nil *** -#### func IsHasNil(v ...V) bool +#### func IsHasNil\[V any\](v ...V) bool > 检查指定的值是否存在 nil diff --git a/utils/geometry/README.md b/utils/geometry/README.md index 9bed1fc..238a8bb 100644 --- a/utils/geometry/README.md +++ b/utils/geometry/README.md @@ -132,7 +132,7 @@ geometry 旨在提供一组用于处理几何形状和计算几何属性的函 *** ## 详情信息 -#### func NewCircle(radius V, points int) Circle[V] +#### func NewCircle\[V generic.SignedNumber\](radius V, points int) Circle[V] > 通过传入圆的半径和需要的点数量,生成一个圆 @@ -146,7 +146,7 @@ func ExampleNewCircle() { ``` *** -#### func CalcCircleCentroidDistance(circle1 Circle[V], circle2 Circle[V]) V +#### func CalcCircleCentroidDistance\[V generic.SignedNumber\](circle1 Circle[V], circle2 Circle[V]) V > 计算两个圆质心距离 @@ -156,133 +156,133 @@ func ExampleNewCircle() { > 获取特定方向的对立方向 *** -#### func GetDirectionNextWithCoordinate(direction Direction, x V, y V) (nx V, ny V) +#### func GetDirectionNextWithCoordinate\[V generic.SignedNumber\](direction Direction, x V, y V) (nx V, ny V) > 获取特定方向上的下一个坐标 *** -#### func GetDirectionNextWithPoint(direction Direction, point Point[V]) Point[V] +#### func GetDirectionNextWithPoint\[V generic.SignedNumber\](direction Direction, point Point[V]) Point[V] > 获取特定方向上的下一个坐标 *** -#### func GetDirectionNextWithPos(direction Direction, width V, pos V) V +#### func GetDirectionNextWithPos\[V generic.SignedNumber\](direction Direction, width V, pos V) V > 获取位置在特定宽度和特定方向上的下一个位置 > - 需要注意的是,在左右方向时,当下一个位置不在矩形区域内时,将会返回上一行的末位置或下一行的首位置 *** -#### func CalcDirection(x1 V, y1 V, x2 V, y2 V) Direction +#### func CalcDirection\[V generic.SignedNumber\](x1 V, y1 V, x2 V, y2 V) Direction > 计算点2位于点1的方向 *** -#### func CalcDistanceWithCoordinate(x1 V, y1 V, x2 V, y2 V) V +#### func CalcDistanceWithCoordinate\[V generic.SignedNumber\](x1 V, y1 V, x2 V, y2 V) V > 计算两点之间的距离 *** -#### func CalcDistanceWithPoint(point1 Point[V], point2 Point[V]) V +#### func CalcDistanceWithPoint\[V generic.SignedNumber\](point1 Point[V], point2 Point[V]) V > 计算两点之间的距离 *** -#### func CalcDistanceSquared(x1 V, y1 V, x2 V, y2 V) V +#### func CalcDistanceSquared\[V generic.SignedNumber\](x1 V, y1 V, x2 V, y2 V) V > 计算两点之间的平方距离 > - 这个函数的主要用途是在需要计算两点之间距离的情况下,但不需要得到实际的距离值,而只需要比较距离大小。因为平方根运算相对较为耗时,所以在只需要比较大小的情况下,通常会使用平方距离。 *** -#### func CalcAngle(x1 V, y1 V, x2 V, y2 V) V +#### func CalcAngle\[V generic.SignedNumber\](x1 V, y1 V, x2 V, y2 V) V > 计算点2位于点1之间的角度 *** -#### func CalcNewCoordinate(x V, y V, angle V, distance V) (newX V, newY V) +#### func CalcNewCoordinate\[V generic.SignedNumber\](x V, y V, angle V, distance V) (newX V, newY V) > 根据给定的x、y坐标、角度和距离计算新的坐标 *** -#### func CalcRadianWithAngle(angle V) V +#### func CalcRadianWithAngle\[V generic.SignedNumber\](angle V) V > 根据角度 angle 计算弧度 *** -#### func CalcAngleDifference(angleA V, angleB V) V +#### func CalcAngleDifference\[V generic.SignedNumber\](angleA V, angleB V) V > 计算两个角度之间的最小角度差 *** -#### func CalcRayIsIntersect(x V, y V, angle V, shape Shape[V]) bool +#### func CalcRayIsIntersect\[V generic.SignedNumber\](x V, y V, angle V, shape Shape[V]) bool > 根据给定的位置和角度生成射线,检测射线是否与多边形发生碰撞 *** -#### func NewLineSegment(start Point[V], end Point[V]) LineSegment[V] +#### func NewLineSegment\[V generic.SignedNumber\](start Point[V], end Point[V]) LineSegment[V] > 创建一根线段 *** -#### func NewLineSegmentCap(start Point[V], end Point[V], data Data) LineSegmentCap[V, Data] +#### func NewLineSegmentCap\[V generic.SignedNumber, Data any\](start Point[V], end Point[V], data Data) LineSegmentCap[V, Data] > 创建一根包含数据的线段 *** -#### func NewLineSegmentCapWithLine(line LineSegment[V], data Data) LineSegmentCap[V, Data] +#### func NewLineSegmentCapWithLine\[V generic.SignedNumber, Data any\](line LineSegment[V], data Data) LineSegmentCap[V, Data] > 通过已有线段创建一根包含数据的线段 *** -#### func ConvertLineSegmentGeneric(line LineSegment[V]) LineSegment[TO] +#### func ConvertLineSegmentGeneric\[V generic.SignedNumber, TO generic.SignedNumber\](line LineSegment[V]) LineSegment[TO] > 转换线段的泛型类型为特定类型 *** -#### func PointOnLineSegmentWithCoordinate(x1 V, y1 V, x2 V, y2 V, x V, y V) bool +#### func PointOnLineSegmentWithCoordinate\[V generic.SignedNumber\](x1 V, y1 V, x2 V, y2 V, x V, y V) bool > 通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上 *** -#### func PointOnLineSegmentWithPos(width V, pos1 V, pos2 V, pos V) bool +#### func PointOnLineSegmentWithPos\[V generic.SignedNumber\](width V, pos1 V, pos2 V, pos V) bool > 通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上 *** -#### func PointOnLineSegmentWithPoint(point1 Point[V], point2 Point[V], point Point[V]) bool +#### func PointOnLineSegmentWithPoint\[V generic.SignedNumber\](point1 Point[V], point2 Point[V], point Point[V]) bool > 通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上 *** -#### func PointOnLineSegmentWithCoordinateInBounds(x1 V, y1 V, x2 V, y2 V, x V, y V) bool +#### func PointOnLineSegmentWithCoordinateInBounds\[V generic.SignedNumber\](x1 V, y1 V, x2 V, y2 V, x V, y V) bool > 通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上 > - 与 PointOnLineSegmentWithCoordinate 不同的是, PointOnLineSegmentWithCoordinateInBounds 中会判断线段及点的位置是否正确 *** -#### func PointOnLineSegmentWithPosInBounds(width V, pos1 V, pos2 V, pos V) bool +#### func PointOnLineSegmentWithPosInBounds\[V generic.SignedNumber\](width V, pos1 V, pos2 V, pos V) bool > 通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上 > - 与 PointOnLineSegmentWithPos 不同的是, PointOnLineSegmentWithPosInBounds 中会判断线段及点的位置是否正确 *** -#### func PointOnLineSegmentWithPointInBounds(point1 Point[V], point2 Point[V], point Point[V]) bool +#### func PointOnLineSegmentWithPointInBounds\[V generic.SignedNumber\](point1 Point[V], point2 Point[V], point Point[V]) bool > 通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上 > - 与 PointOnLineSegmentWithPoint 不同的是, PointOnLineSegmentWithPointInBounds 中会判断线段及点的位置是否正确 *** -#### func CalcLineSegmentIsCollinear(line1 LineSegment[V], line2 LineSegment[V], tolerance V) bool +#### func CalcLineSegmentIsCollinear\[V generic.SignedNumber\](line1 LineSegment[V], line2 LineSegment[V], tolerance V) bool > 检查两条线段在一个误差内是否共线 > - 共线是指两条线段在同一直线上,即它们的延长线可以重合 *** -#### func CalcLineSegmentIsOverlap(line1 LineSegment[V], line2 LineSegment[V]) (line LineSegment[V], overlap bool) +#### func CalcLineSegmentIsOverlap\[V generic.SignedNumber\](line1 LineSegment[V], line2 LineSegment[V]) (line LineSegment[V], overlap bool) > 通过对点进行排序来检查两条共线线段是否重叠,返回重叠线段 *** -#### func CalcLineSegmentIsIntersect(line1 LineSegment[V], line2 LineSegment[V]) bool +#### func CalcLineSegmentIsIntersect\[V generic.SignedNumber\](line1 LineSegment[V], line2 LineSegment[V]) bool > 计算两条线段是否相交 @@ -305,17 +305,17 @@ func TestCalcLineSegmentIsIntersect(t *testing.T) { *** -#### func CalcLineSegmentSlope(line LineSegment[V]) V +#### func CalcLineSegmentSlope\[V generic.SignedNumber\](line LineSegment[V]) V > 计算线段的斜率 *** -#### func CalcLineSegmentIntercept(line LineSegment[V]) V +#### func CalcLineSegmentIntercept\[V generic.SignedNumber\](line LineSegment[V]) V > 计算线段的截距 *** -#### func NewPoint(x V, y V) Point[V] +#### func NewPoint\[V generic.SignedNumber\](x V, y V) Point[V] > 创建一个由 x、y 坐标组成的点 @@ -337,146 +337,146 @@ func TestNewPoint(t *testing.T) { *** -#### func NewPointCap(x V, y V) PointCap[V, D] +#### func NewPointCap\[V generic.SignedNumber, D any\](x V, y V) PointCap[V, D] > 创建一个由 x、y 坐标组成的点,这个点具有一个数据容量 *** -#### func NewPointCapWithData(x V, y V, data D) PointCap[V, D] +#### func NewPointCapWithData\[V generic.SignedNumber, D any\](x V, y V, data D) PointCap[V, D] > 通过设置数据的方式创建一个由 x、y 坐标组成的点,这个点具有一个数据容量 *** -#### func NewPointCapWithPoint(point Point[V], data D) PointCap[V, D] +#### func NewPointCapWithPoint\[V generic.SignedNumber, D any\](point Point[V], data D) PointCap[V, D] > 通过设置数据的方式创建一个由已有坐标组成的点,这个点具有一个数据容量 *** -#### func CoordinateToPoint(x V, y V) Point[V] +#### func CoordinateToPoint\[V generic.SignedNumber\](x V, y V) Point[V] > 将坐标转换为x、y的坐标数组 *** -#### func CoordinateToPos(width V, x V, y V) V +#### func CoordinateToPos\[V generic.SignedNumber\](width V, x V, y V) V > 将坐标转换为二维数组的顺序位置坐标 > - 需要确保x的取值范围必须小于width,或者将会得到不正确的值 *** -#### func PointToCoordinate(position Point[V]) (x V, y V) +#### func PointToCoordinate\[V generic.SignedNumber\](position Point[V]) (x V, y V) > 将坐标数组转换为x和y坐标 *** -#### func PointToPos(width V, xy Point[V]) V +#### func PointToPos\[V generic.SignedNumber\](width V, xy Point[V]) V > 将坐标转换为二维数组的顺序位置 > - 需要确保x的取值范围必须小于width,或者将会得到不正确的值 *** -#### func PosToCoordinate(width V, pos V) (x V, y V) +#### func PosToCoordinate\[V generic.SignedNumber\](width V, pos V) (x V, y V) > 通过宽度将一个二维数组的顺序位置转换为xy坐标 *** -#### func PosToPoint(width V, pos V) Point[V] +#### func PosToPoint\[V generic.SignedNumber\](width V, pos V) Point[V] > 通过宽度将一个二维数组的顺序位置转换为x、y的坐标数组 *** -#### func PosToCoordinateX(width V, pos V) V +#### func PosToCoordinateX\[V generic.SignedNumber\](width V, pos V) V > 通过宽度将一个二维数组的顺序位置转换为X坐标 *** -#### func PosToCoordinateY(width V, pos V) V +#### func PosToCoordinateY\[V generic.SignedNumber\](width V, pos V) V > 通过宽度将一个二维数组的顺序位置转换为Y坐标 *** -#### func PointCopy(point Point[V]) Point[V] +#### func PointCopy\[V generic.SignedNumber\](point Point[V]) Point[V] > 复制一个坐标数组 *** -#### func PointToPosWithMulti(width V, points ...Point[V]) []V +#### func PointToPosWithMulti\[V generic.SignedNumber\](width V, points ...Point[V]) []V > 将一组坐标转换为二维数组的顺序位置 > - 需要确保x的取值范围必须小于width,或者将会得到不正确的值 *** -#### func PosToPointWithMulti(width V, positions ...V) []Point[V] +#### func PosToPointWithMulti\[V generic.SignedNumber\](width V, positions ...V) []Point[V] > 将一组二维数组的顺序位置转换为一组数组坐标 *** -#### func PosSameRow(width V, pos1 V, pos2 V) bool +#### func PosSameRow\[V generic.SignedNumber\](width V, pos1 V, pos2 V) bool > 返回两个顺序位置在同一宽度是否位于同一行 *** -#### func DoublePointToCoordinate(point1 Point[V], point2 Point[V]) (x1 V, y1 V, x2 V, y2 V) +#### func DoublePointToCoordinate\[V generic.SignedNumber\](point1 Point[V], point2 Point[V]) (x1 V, y1 V, x2 V, y2 V) > 将两个位置转换为 x1, y1, x2, y2 的坐标进行返回 *** -#### func CalcProjectionPoint(line LineSegment[V], point Point[V]) Point[V] +#### func CalcProjectionPoint\[V generic.SignedNumber\](line LineSegment[V], point Point[V]) Point[V] > 计算一个点到一条线段的最近点(即投影点)的。这个函数接收一个点和一条线段作为输入,线段由两个端点组成。 > - 该函数的主要用于需要计算一个点到一条线段的最近点的情况下 *** -#### func GetAdjacentTranslatePos(matrix []T, width P, pos P) (result []P) +#### func GetAdjacentTranslatePos\[T any, P generic.SignedNumber\](matrix []T, width P, pos P) (result []P) > 获取一个连续位置的矩阵中,特定位置相邻的最多四个平移方向(上下左右)的位置 *** -#### func GetAdjacentTranslateCoordinateXY(matrix [][]T, x P, y P) (result []Point[P]) +#### func GetAdjacentTranslateCoordinateXY\[T any, P generic.SignedNumber\](matrix [][]T, x P, y P) (result []Point[P]) > 获取一个基于 x、y 的二维矩阵中,特定位置相邻的最多四个平移方向(上下左右)的位置 *** -#### func GetAdjacentTranslateCoordinateYX(matrix [][]T, x P, y P) (result []Point[P]) +#### func GetAdjacentTranslateCoordinateYX\[T any, P generic.SignedNumber\](matrix [][]T, x P, y P) (result []Point[P]) > 获取一个基于 y、x 的二维矩阵中,特定位置相邻的最多四个平移方向(上下左右)的位置 *** -#### func GetAdjacentDiagonalsPos(matrix []T, width P, pos P) (result []P) +#### func GetAdjacentDiagonalsPos\[T any, P generic.SignedNumber\](matrix []T, width P, pos P) (result []P) > 获取一个连续位置的矩阵中,特定位置相邻的对角线最多四个方向的位置 *** -#### func GetAdjacentDiagonalsCoordinateXY(matrix [][]T, x P, y P) (result []Point[P]) +#### func GetAdjacentDiagonalsCoordinateXY\[T any, P generic.SignedNumber\](matrix [][]T, x P, y P) (result []Point[P]) > 获取一个基于 x、y 的二维矩阵中,特定位置相邻的对角线最多四个方向的位置 *** -#### func GetAdjacentDiagonalsCoordinateYX(matrix [][]T, x P, y P) (result []Point[P]) +#### func GetAdjacentDiagonalsCoordinateYX\[T any, P generic.SignedNumber\](matrix [][]T, x P, y P) (result []Point[P]) > 获取一个基于 tx 的二维矩阵中,特定位置相邻的对角线最多四个方向的位置 *** -#### func GetAdjacentPos(matrix []T, width P, pos P) (result []P) +#### func GetAdjacentPos\[T any, P generic.SignedNumber\](matrix []T, width P, pos P) (result []P) > 获取一个连续位置的矩阵中,特定位置相邻的最多八个方向的位置 *** -#### func GetAdjacentCoordinateXY(matrix [][]T, x P, y P) (result []Point[P]) +#### func GetAdjacentCoordinateXY\[T any, P generic.SignedNumber\](matrix [][]T, x P, y P) (result []Point[P]) > 获取一个基于 x、y 的二维矩阵中,特定位置相邻的最多八个方向的位置 *** -#### func GetAdjacentCoordinateYX(matrix [][]T, x P, y P) (result []Point[P]) +#### func GetAdjacentCoordinateYX\[T any, P generic.SignedNumber\](matrix [][]T, x P, y P) (result []Point[P]) > 获取一个基于 yx 的二维矩阵中,特定位置相邻的最多八个方向的位置 *** -#### func CoordinateMatrixToPosMatrix(matrix [][]V) (width int, posMatrix []V) +#### func CoordinateMatrixToPosMatrix\[V any\](matrix [][]V) (width int, posMatrix []V) > 将二维矩阵转换为顺序的二维矩阵 *** -#### func GetShapeCoverageAreaWithPoint(points ...Point[V]) (left V, right V, top V, bottom V) +#### func GetShapeCoverageAreaWithPoint\[V generic.SignedNumber\](points ...Point[V]) (left V, right V, top V, bottom V) > 通过传入的一组坐标 points 计算一个图形覆盖的矩形范围 @@ -521,7 +521,7 @@ func TestGetShapeCoverageAreaWithPoint(t *testing.T) { *** -#### func GetShapeCoverageAreaWithPos(width V, positions ...V) (left V, right V, top V, bottom V) +#### func GetShapeCoverageAreaWithPos\[V generic.SignedNumber\](width V, positions ...V) (left V, right V, top V, bottom V) > 通过传入的一组坐标 positions 计算一个图形覆盖的矩形范围 @@ -558,7 +558,7 @@ func TestGetShapeCoverageAreaWithPos(t *testing.T) { *** -#### func CoverageAreaBoundless(l V, r V, t V, b V) (left V, right V, top V, bottom V) +#### func CoverageAreaBoundless\[V generic.SignedNumber\](l V, r V, t V, b V) (left V, right V, top V, bottom V) > 将一个图形覆盖矩形范围设置为无边的 > - 无边化表示会将多余的部分进行裁剪,例如图形左边从 2 开始的时候,那么左边将会被裁剪到从 0 开始 @@ -596,7 +596,7 @@ func TestCoverageAreaBoundless(t *testing.T) { *** -#### func GenerateShapeOnRectangle(points ...Point[V]) (result []PointCap[V, bool]) +#### func GenerateShapeOnRectangle\[V generic.SignedNumber\](points ...Point[V]) (result []PointCap[V, bool]) > 生成一组二维坐标的形状 > - 这个形状将被在一个刚好能容纳形状的矩形中表示 @@ -638,44 +638,44 @@ func TestGenerateShapeOnRectangle(t *testing.T) { *** -#### func GenerateShapeOnRectangleWithCoordinate(points ...Point[V]) (result [][]bool) +#### func GenerateShapeOnRectangleWithCoordinate\[V generic.SignedNumber\](points ...Point[V]) (result [][]bool) > 生成一组二维坐标的形状 > - 这个形状将被在一个刚好能容纳形状的矩形中表示 > - 为 true 的位置表示了形状的每一个点 *** -#### func GetExpressibleRectangleBySize(width V, height V, minWidth V, minHeight V) (result []Point[V]) +#### func GetExpressibleRectangleBySize\[V generic.SignedNumber\](width V, height V, minWidth V, minHeight V) (result []Point[V]) > 获取一个宽高可表达的所有特定尺寸以上的矩形形状 > - 返回值表示了每一个矩形右下角的x,y位置(左上角始终为0, 0) > - 矩形尺寸由大到小 *** -#### func GetExpressibleRectangle(width V, height V) (result []Point[V]) +#### func GetExpressibleRectangle\[V generic.SignedNumber\](width V, height V) (result []Point[V]) > 获取一个宽高可表达的所有矩形形状 > - 返回值表示了每一个矩形右下角的x,y位置(左上角始终为0, 0) > - 矩形尺寸由大到小 *** -#### func GetRectangleFullPointsByXY(startX V, startY V, endX V, endY V) (result []Point[V]) +#### func GetRectangleFullPointsByXY\[V generic.SignedNumber\](startX V, startY V, endX V, endY V) (result []Point[V]) > 通过开始结束坐标获取一个矩形包含的所有点 > - 例如 1,1 到 2,2 的矩形结果为 1,1 2,1 1,2 2,2 *** -#### func GetRectangleFullPoints(width V, height V) (result []Point[V]) +#### func GetRectangleFullPoints\[V generic.SignedNumber\](width V, height V) (result []Point[V]) > 获取一个矩形填充满后包含的所有点 *** -#### func GetRectangleFullPos(width V, height V) (result []V) +#### func GetRectangleFullPos\[V generic.SignedNumber\](width V, height V) (result []V) > 获取一个矩形填充满后包含的所有位置 *** -#### func CalcRectangleCentroid(shape Shape[V]) Point[V] +#### func CalcRectangleCentroid\[V generic.SignedNumber\](shape Shape[V]) Point[V] > 计算矩形质心 > - 非多边形质心计算,仅为顶点的平均值 - 该区域中多边形因子的适当质心 @@ -691,7 +691,7 @@ func TestGenerateShapeOnRectangle(t *testing.T) { > 设置 Shape.String 是没有边界的 *** -#### func NewShape(points ...Point[V]) Shape[V] +#### func NewShape\[V generic.SignedNumber\](points ...Point[V]) Shape[V] > 通过多个点生成一个形状进行返回 @@ -733,7 +733,7 @@ func TestNewShape(t *testing.T) { *** -#### func NewShapeWithString(rows []string, point rune) (shape Shape[V]) +#### func NewShapeWithString\[V generic.SignedNumber\](rows []string, point rune) (shape Shape[V]) > 通过字符串将指定 rune 转换为点位置生成形状进行返回 > - 每个点的顺序从上到下,从左到右 @@ -775,27 +775,27 @@ func TestNewShapeWithString(t *testing.T) { *** -#### func CalcBoundingRadius(shape Shape[V]) V +#### func CalcBoundingRadius\[V generic.SignedNumber\](shape Shape[V]) V > 计算多边形转换为圆的半径 *** -#### func CalcBoundingRadiusWithCentroid(shape Shape[V], centroid Point[V]) V +#### func CalcBoundingRadiusWithCentroid\[V generic.SignedNumber\](shape Shape[V], centroid Point[V]) V > 计算多边形在特定质心下圆的半径 *** -#### func CalcTriangleTwiceArea(a Point[V], b Point[V], c Point[V]) V +#### func CalcTriangleTwiceArea\[V generic.SignedNumber\](a Point[V], b Point[V], c Point[V]) V > 计算由 a、b、c 三个点组成的三角形的面积的两倍 *** -#### func IsPointOnEdge(edges []LineSegment[V], point Point[V]) bool +#### func IsPointOnEdge\[V generic.SignedNumber\](edges []LineSegment[V], point Point[V]) bool > 检查点是否在 edges 的任意一条边上 *** -#### func ProjectionPointToShape(point Point[V], shape Shape[V]) (Point[V], V) +#### func ProjectionPointToShape\[V generic.SignedNumber\](point Point[V], shape Shape[V]) (Point[V], V) > 将一个点投影到一个多边形上,找到离该点最近的投影点,并返回投影点和距离 diff --git a/utils/geometry/astar/README.md b/utils/geometry/astar/README.md index 938465c..b44daf6 100644 --- a/utils/geometry/astar/README.md +++ b/utils/geometry/astar/README.md @@ -35,7 +35,7 @@ astar 提供用于实现 A* 算法的函数和数据结构。A* 算法是一种 *** ## 详情信息 -#### func Find(graph Graph[Node], start Node, end Node, cost func (a Node) V, heuristic func (a Node) V) []Node +#### func Find\[Node comparable, V generic.SignedNumber\](graph Graph[Node], start Node, end Node, cost func (a Node) V, heuristic func (a Node) V) []Node > 使用 A* 算法在导航网格上查找从起点到终点的最短路径,并返回路径上的节点序列。 > diff --git a/utils/geometry/dp/README.md b/utils/geometry/dp/README.md index 0250b7d..1eaf3ce 100644 --- a/utils/geometry/dp/README.md +++ b/utils/geometry/dp/README.md @@ -35,7 +35,7 @@ dp (DistributionPattern) 提供用于在二维数组中根据不同的特征标 *** ## 详情信息 -#### func NewDistributionPattern(sameKindVerifyHandle func (itemA Item) bool) *DistributionPattern[Item] +#### func NewDistributionPattern\[Item any\](sameKindVerifyHandle func (itemA Item) bool) *DistributionPattern[Item] > 构建一个分布图实例 diff --git a/utils/geometry/matrix/README.md b/utils/geometry/matrix/README.md index 9d45d0e..c8972d1 100644 --- a/utils/geometry/matrix/README.md +++ b/utils/geometry/matrix/README.md @@ -30,7 +30,7 @@ matrix 提供了一个简单的二维数组的实现 *** ## 详情信息 -#### func NewMatrix(width int, height int) *Matrix[T] +#### func NewMatrix\[T any\](width int, height int) *Matrix[T] > 生成特定宽高的二维矩阵 > - 虽然提供了通过x、y坐标的操作函数,但是建议无论如何使用pos进行处理 diff --git a/utils/geometry/navmesh/README.md b/utils/geometry/navmesh/README.md index 657620b..04d006e 100644 --- a/utils/geometry/navmesh/README.md +++ b/utils/geometry/navmesh/README.md @@ -33,7 +33,7 @@ navmesh 提供了用于导航网格处理的函数和数据结构。导航网格 *** ## 详情信息 -#### func NewNavMesh(shapes []geometry.Shape[V], meshShrinkAmount V) *NavMesh[V] +#### func NewNavMesh\[V generic.SignedNumber\](shapes []geometry.Shape[V], meshShrinkAmount V) *NavMesh[V] > 创建一个新的导航网格,并返回一个指向该导航网格的指针。 > diff --git a/utils/hub/README.md b/utils/hub/README.md index d3bdaaa..63d2ed7 100644 --- a/utils/hub/README.md +++ b/utils/hub/README.md @@ -30,7 +30,7 @@ *** ## 详情信息 -#### func NewObjectPool(generator func () *T, releaser func (data *T)) *ObjectPool[*T] +#### func NewObjectPool\[T any\](generator func () *T, releaser func (data *T)) *ObjectPool[*T] > 创建一个 ObjectPool diff --git a/utils/huge/README.md b/utils/huge/README.md index 83c9e5b..1f8e8a6 100644 --- a/utils/huge/README.md +++ b/utils/huge/README.md @@ -34,7 +34,7 @@ *** ## 详情信息 -#### func NewFloat(x T) *Float +#### func NewFloat\[T generic.Number\](x T) *Float > 创建一个 Float @@ -45,7 +45,7 @@ > - 如果字符串不是一个合法的数字,则返回 0 *** -#### func NewInt(x T) *Int +#### func NewInt\[T generic.Number\](x T) *Int > 创建一个 Int diff --git a/utils/leaderboard/README.md b/utils/leaderboard/README.md index 9080f55..3cd06c1 100644 --- a/utils/leaderboard/README.md +++ b/utils/leaderboard/README.md @@ -34,7 +34,7 @@ *** ## 详情信息 -#### func NewBinarySearch(options ...BinarySearchOption[CompetitorID, Score]) *BinarySearch[CompetitorID, Score] +#### func NewBinarySearch\[CompetitorID comparable, Score generic.Ordered\](options ...BinarySearchOption[CompetitorID, Score]) *BinarySearch[CompetitorID, Score] > 创建一个基于内存的二分查找排行榜 @@ -49,13 +49,13 @@ func ExampleNewBinarySearch() { ``` *** -#### func WithBinarySearchCount(rankCount int) BinarySearchOption[CompetitorID, Score] +#### func WithBinarySearchCount\[CompetitorID comparable, Score generic.Ordered\](rankCount int) BinarySearchOption[CompetitorID, Score] > 通过限制排行榜竞争者数量来创建排行榜 > - 默认情况下允许100位竞争者 *** -#### func WithBinarySearchASC() BinarySearchOption[CompetitorID, Score] +#### func WithBinarySearchASC\[CompetitorID comparable, Score generic.Ordered\]() BinarySearchOption[CompetitorID, Score] > 通过升序的方式创建排行榜 > - 默认情况下为降序 diff --git a/utils/log/README.md b/utils/log/README.md index 7beab82..16682a5 100644 --- a/utils/log/README.md +++ b/utils/log/README.md @@ -186,132 +186,132 @@ > 构造一个带有字符串值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null" *** -#### func Int(key string, val I) slog.Attr +#### func Int\[I generic.Integer\](key string, val I) slog.Attr > 构造一个带有整数值的字段 *** -#### func IntP(key string, val *I) slog.Attr +#### func IntP\[I generic.Integer\](key string, val *I) slog.Attr > 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null" *** -#### func Int8(key string, val I) slog.Attr +#### func Int8\[I generic.Integer\](key string, val I) slog.Attr > 构造一个带有整数值的字段 *** -#### func Int8P(key string, val *I) slog.Attr +#### func Int8P\[I generic.Integer\](key string, val *I) slog.Attr > 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null" *** -#### func Int16(key string, val I) slog.Attr +#### func Int16\[I generic.Integer\](key string, val I) slog.Attr > 构造一个带有整数值的字段 *** -#### func Int16P(key string, val *I) slog.Attr +#### func Int16P\[I generic.Integer\](key string, val *I) slog.Attr > 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null" *** -#### func Int32(key string, val I) slog.Attr +#### func Int32\[I generic.Integer\](key string, val I) slog.Attr > 构造一个带有整数值的字段 *** -#### func Int32P(key string, val *I) slog.Attr +#### func Int32P\[I generic.Integer\](key string, val *I) slog.Attr > 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null" *** -#### func Int64(key string, val I) slog.Attr +#### func Int64\[I generic.Integer\](key string, val I) slog.Attr > 构造一个带有整数值的字段 *** -#### func Int64P(key string, val *I) slog.Attr +#### func Int64P\[I generic.Integer\](key string, val *I) slog.Attr > 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null" *** -#### func Uint(key string, val I) slog.Attr +#### func Uint\[I generic.Integer\](key string, val I) slog.Attr > 构造一个带有整数值的字段 *** -#### func UintP(key string, val *I) slog.Attr +#### func UintP\[I generic.Integer\](key string, val *I) slog.Attr > 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null" *** -#### func Uint8(key string, val I) slog.Attr +#### func Uint8\[I generic.Integer\](key string, val I) slog.Attr > 构造一个带有整数值的字段 *** -#### func Uint8P(key string, val *I) slog.Attr +#### func Uint8P\[I generic.Integer\](key string, val *I) slog.Attr > 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null" *** -#### func Uint16(key string, val I) slog.Attr +#### func Uint16\[I generic.Integer\](key string, val I) slog.Attr > 构造一个带有整数值的字段 *** -#### func Uint16P(key string, val *I) slog.Attr +#### func Uint16P\[I generic.Integer\](key string, val *I) slog.Attr > 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null" *** -#### func Uint32(key string, val I) slog.Attr +#### func Uint32\[I generic.Integer\](key string, val I) slog.Attr > 构造一个带有整数值的字段 *** -#### func Uint32P(key string, val *I) slog.Attr +#### func Uint32P\[I generic.Integer\](key string, val *I) slog.Attr > 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null" *** -#### func Uint64(key string, val I) slog.Attr +#### func Uint64\[I generic.Integer\](key string, val I) slog.Attr > 构造一个带有整数值的字段 *** -#### func Uint64P(key string, val *I) slog.Attr +#### func Uint64P\[I generic.Integer\](key string, val *I) slog.Attr > 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null" *** -#### func Float(key string, val F) slog.Attr +#### func Float\[F generic.Float\](key string, val F) slog.Attr > 构造一个带有浮点值的字段 *** -#### func FloatP(key string, val *F) slog.Attr +#### func FloatP\[F generic.Float\](key string, val *F) slog.Attr > 构造一个带有浮点值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null" *** -#### func Float32(key string, val F) slog.Attr +#### func Float32\[F generic.Float\](key string, val F) slog.Attr > 构造一个带有浮点值的字段 *** -#### func Float32P(key string, val *F) slog.Attr +#### func Float32P\[F generic.Float\](key string, val *F) slog.Attr > 构造一个带有浮点值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null" *** -#### func Float64(key string, val F) slog.Attr +#### func Float64\[F generic.Float\](key string, val F) slog.Attr > 构造一个带有浮点值的字段 *** -#### func Float64P(key string, val *F) slog.Attr +#### func Float64P\[F generic.Float\](key string, val *F) slog.Attr > 构造一个带有浮点值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null" diff --git a/utils/maths/README.md b/utils/maths/README.md index 8bde01c..0b49848 100644 --- a/utils/maths/README.md +++ b/utils/maths/README.md @@ -52,12 +52,12 @@ *** ## 详情信息 -#### func Compare(a V, expression CompareExpression, b V) bool +#### func Compare\[V generic.Ordered\](a V, expression CompareExpression, b V) bool > 根据特定表达式比较两个值 *** -#### func IsContinuity(values S) bool +#### func IsContinuity\[S ~[]V, V generic.Integer\](values S) bool > 检查一组值是否连续 @@ -72,7 +72,7 @@ func ExampleIsContinuity() { ``` *** -#### func IsContinuityWithSort(values S) bool +#### func IsContinuityWithSort\[S ~[]V, V generic.Integer\](values S) bool > 检查一组值排序后是否连续 @@ -92,57 +92,57 @@ func ExampleIsContinuity() { > 整数幂运算 *** -#### func Min(a V, b V) V +#### func Min\[V generic.Number\](a V, b V) V > 返回两个数之中较小的值 *** -#### func Max(a V, b V) V +#### func Max\[V generic.Number\](a V, b V) V > 返回两个数之中较大的值 *** -#### func MinMax(a V, b V) (min V, max V) +#### func MinMax\[V generic.Number\](a V, b V) (min V, max V) > 将两个数按照较小的和较大的顺序进行返回 *** -#### func MaxMin(a V, b V) (max V, min V) +#### func MaxMin\[V generic.Number\](a V, b V) (max V, min V) > 将两个数按照较大的和较小的顺序进行返回 *** -#### func Clamp(value V, min V, max V) V +#### func Clamp\[V generic.Number\](value V, min V, max V) V > 将给定值限制在最小值和最大值之间 *** -#### func Tolerance(value1 V, value2 V, tolerance V) bool +#### func Tolerance\[V generic.Number\](value1 V, value2 V, tolerance V) bool > 检查两个值是否在一个误差范围内 *** -#### func Merge(refer V, a V, b V) V +#### func Merge\[V generic.SignedNumber\](refer V, a V, b V) V > 通过一个参考值合并两个数字 *** -#### func UnMerge(refer V, num V) (a V, b V) +#### func UnMerge\[V generic.SignedNumber\](refer V, num V) (a V, b V) > 通过一个参考值取消合并的两个数字 *** -#### func MergeToInt64(v1 V, v2 V) int64 +#### func MergeToInt64\[V generic.SignedNumber\](v1 V, v2 V) int64 > 将两个数字合并为一个 int64 数字 *** -#### func UnMergeInt64(n int64) (V, V) +#### func UnMergeInt64\[V generic.SignedNumber\](n int64) (V, V) > 将一个 int64 数字拆分为两个数字 *** -#### func ToContinuous(nums S) map[V]V +#### func ToContinuous\[S ~[]V, V generic.Integer\](nums S) map[V]V > 将一组非连续的数字转换为从1开始的连续数字 > - 返回值是一个 map,key 是从 1 开始的连续数字,value 是原始数字 @@ -160,7 +160,7 @@ func ExampleToContinuous() { ``` *** -#### func CountDigits(num V) int +#### func CountDigits\[V generic.Number\](num V) int > 接收一个整数 num 作为输入,并返回该数字的位数 @@ -172,22 +172,22 @@ func ExampleToContinuous() { > 过除以10的操作将 num 移动到目标位数上。然后,通过取余运算得到位数上的数值 *** -#### func JoinNumbers(num1 V, n ...V) V +#### func JoinNumbers\[V generic.Number\](num1 V, n ...V) V > 将一组数字连接起来 *** -#### func IsOdd(n V) bool +#### func IsOdd\[V generic.Integer\](n V) bool > 返回 n 是否为奇数 *** -#### func IsEven(n V) bool +#### func IsEven\[V generic.Integer\](n V) bool > 返回 n 是否为偶数 *** -#### func MakeLastDigitsZero(num T, digits int) T +#### func MakeLastDigitsZero\[T generic.Number\](num T, digits int) T > 返回一个新的数,其中 num 的最后 digits 位数被设为零。 > - 函数首先创建一个 10 的 digits 次方的遮罩,然后通过整除和乘以这个遮罩来使 num 的最后 digits 位归零。 diff --git a/utils/memory/README.md b/utils/memory/README.md index 3c23235..81e1057 100644 --- a/utils/memory/README.md +++ b/utils/memory/README.md @@ -38,7 +38,7 @@ > 运行持久化缓存程序 *** -#### func BindPersistCacheProgram(name string, handler OutputParamHandlerFunc, option ...*Option) func () +#### func BindPersistCacheProgram\[OutputParamHandlerFunc any\](name string, handler OutputParamHandlerFunc, option ...*Option) func () > 绑定持久化缓存程序 > - name 持久化缓存程序名称 @@ -52,7 +52,7 @@ > - 所有持久化程序绑定完成后,应该主动调用 Run 函数运行 *** -#### func BindAction(name string, handler Func) Func +#### func BindAction\[Func any\](name string, handler Func) Func > 绑定需要缓存的操作函数 > - name 缓存操作名称 diff --git a/utils/moving/README.md b/utils/moving/README.md index 164b235..5f88634 100644 --- a/utils/moving/README.md +++ b/utils/moving/README.md @@ -37,7 +37,7 @@ *** ## 详情信息 -#### func NewTwoDimensional(options ...TwoDimensionalOption[EID, PosType]) *TwoDimensional[EID, PosType] +#### func NewTwoDimensional\[EID generic.Basic, PosType generic.SignedNumber\](options ...TwoDimensionalOption[EID, PosType]) *TwoDimensional[EID, PosType] > 创建一个用于2D对象移动的实例(TwoDimensional) @@ -74,19 +74,19 @@ func TestNewTwoDimensional(t *testing.T) { *** -#### func WithTwoDimensionalTimeUnit(duration time.Duration) TwoDimensionalOption[EID, PosType] +#### func WithTwoDimensionalTimeUnit\[EID generic.Basic, PosType generic.SignedNumber\](duration time.Duration) TwoDimensionalOption[EID, PosType] > 通过特定时间单位创建 > - 默认单位为1毫秒,最小单位也为1毫秒 *** -#### func WithTwoDimensionalIdleWaitTime(duration time.Duration) TwoDimensionalOption[EID, PosType] +#### func WithTwoDimensionalIdleWaitTime\[EID generic.Basic, PosType generic.SignedNumber\](duration time.Duration) TwoDimensionalOption[EID, PosType] > 通过特定的空闲等待时间创建 > - 默认情况下在没有新的移动计划时将限制 100毫秒 + 移动间隔事件(默认100毫秒) *** -#### func WithTwoDimensionalInterval(duration time.Duration) TwoDimensionalOption[EID, PosType] +#### func WithTwoDimensionalInterval\[EID generic.Basic, PosType generic.SignedNumber\](duration time.Duration) TwoDimensionalOption[EID, PosType] > 通过特定的移动间隔时间创建 diff --git a/utils/random/README.md b/utils/random/README.md index 4747b7f..ee9e3a9 100644 --- a/utils/random/README.md +++ b/utils/random/README.md @@ -119,7 +119,7 @@ > 返回一个随机的布尔值 *** -#### func ProbabilitySlice(getProbabilityHandle func (data T) float64, data ...T) (hit T, miss bool) +#### func ProbabilitySlice\[T any\](getProbabilityHandle func (data T) float64, data ...T) (hit T, miss bool) > 按概率随机从切片中产生一个数据并返回命中的对象及是否未命中 > - 当总概率小于 1 将会发生未命中的情况 @@ -147,7 +147,7 @@ func TestProbabilitySlice(t *testing.T) { *** -#### func ProbabilitySliceIndex(getProbabilityHandle func (data T) float64, data ...T) (hit T, index int, miss bool) +#### func ProbabilitySliceIndex\[T any\](getProbabilityHandle func (data T) float64, data ...T) (hit T, index int, miss bool) > 按概率随机从切片中产生一个数据并返回命中的对象及对象索引以及是否未命中 > - 当总概率小于 1 将会发生未命中的情况 @@ -200,22 +200,22 @@ func TestProbabilitySlice(t *testing.T) { > 返回一个随机产生的hostname。 *** -#### func WeightSlice(getWeightHandle func (data T) int64, data ...T) T +#### func WeightSlice\[T any\](getWeightHandle func (data T) int64, data ...T) T > 按权重随机从切片中产生一个数据并返回 *** -#### func WeightSliceIndex(getWeightHandle func (data T) int64, data ...T) (item T, index int) +#### func WeightSliceIndex\[T any\](getWeightHandle func (data T) int64, data ...T) (item T, index int) > 按权重随机从切片中产生一个数据并返回数据和对应索引 *** -#### func WeightMap(getWeightHandle func (data T) int64, data map[K]T) T +#### func WeightMap\[K comparable, T any\](getWeightHandle func (data T) int64, data map[K]T) T > 按权重随机从map中产生一个数据并返回 *** -#### func WeightMapKey(getWeightHandle func (data T) int64, data map[K]T) (item T, key K) +#### func WeightMapKey\[K comparable, T any\](getWeightHandle func (data T) int64, data map[K]T) (item T, key K) > 按权重随机从map中产生一个数据并返回数据和对应 key diff --git a/utils/reflects/README.md b/utils/reflects/README.md index 950e693..63f0ea6 100644 --- a/utils/reflects/README.md +++ b/utils/reflects/README.md @@ -32,22 +32,22 @@ *** ## 详情信息 -#### func WrapperFunc(f any, wrapper func (call func ( []reflect.Value) []reflect.Value) func (args []reflect.Value) []reflect.Value) (wf Func, err error) +#### func WrapperFunc\[Func any\](f any, wrapper func (call func ( []reflect.Value) []reflect.Value) func (args []reflect.Value) []reflect.Value) (wf Func, err error) > 包装函数 *** -#### func WrapperFuncBefore2After(f Func, before func (), after func ()) (wf Func, err error) +#### func WrapperFuncBefore2After\[Func any\](f Func, before func (), after func ()) (wf Func, err error) > 包装函数,前置函数执行前,后置函数执行后 *** -#### func WrapperFuncBefore(f Func, before func ()) (wf Func, err error) +#### func WrapperFuncBefore\[Func any\](f Func, before func ()) (wf Func, err error) > 包装函数,前置函数执行前 *** -#### func WrapperFuncAfter(f Func, after func ()) (wf Func, err error) +#### func WrapperFuncAfter\[Func any\](f Func, after func ()) (wf Func, err error) > 包装函数,后置函数执行后 @@ -67,7 +67,7 @@ > 拷贝 *** -#### func GetPointer(src T) reflect.Value +#### func GetPointer\[T any\](src T) reflect.Value > 获取指针 diff --git a/utils/sole/README.md b/utils/sole/README.md index 5c238b0..040be62 100644 --- a/utils/sole/README.md +++ b/utils/sole/README.md @@ -75,7 +75,7 @@ > 重置特定命名空间的唯一标识符 *** -#### func NewOnce() *Once[V] +#### func NewOnce\[V any\]() *Once[V] > 创建一个用于数据取值去重的结构实例 diff --git a/utils/sorts/README.md b/utils/sorts/README.md index bc1ef79..29f8404 100644 --- a/utils/sorts/README.md +++ b/utils/sorts/README.md @@ -25,7 +25,7 @@ *** ## 详情信息 -#### func Topological(slice S, queryIndexHandler func (item V) Index, queryDependsHandler func (item V) []Index) (S, error) +#### func Topological\[S ~[]V, Index comparable, V any\](slice S, queryIndexHandler func (item V) Index, queryDependsHandler func (item V) []Index) (S, error) > 拓扑排序是一种对有向图进行排序的算法,它可以用来解决一些依赖关系的问题,比如计算字段的依赖关系。拓扑排序会将存在依赖关系的元素进行排序,使得依赖关系的元素总是排在被依赖的元素之前。 > - slice: 需要排序的切片 diff --git a/utils/super/README.md b/utils/super/README.md index 700d5ad..8c80309 100644 --- a/utils/super/README.md +++ b/utils/super/README.md @@ -104,18 +104,18 @@ *** ## 详情信息 -#### func NewBitSet(bits ...Bit) *BitSet[Bit] +#### func NewBitSet\[Bit generic.Integer\](bits ...Bit) *BitSet[Bit] > 通过指定的 Bit 位创建一个 BitSet *** -#### func TryWriteChannel(ch chan T, data T) bool +#### func TryWriteChannel\[T any\](ch chan T, data T) bool > 尝试写入 channel,如果 channel 无法写入则忽略,返回是否写入成功 > - 无法写入的情况包括:channel 已满、channel 已关闭 *** -#### func TryWriteChannelByHandler(ch chan T, data T, handler func ()) +#### func TryWriteChannelByHandler\[T any\](ch chan T, data T, handler func ()) > 尝试写入 channel,如果 channel 无法写入则执行 handler > - 无法写入的情况包括:channel 已满、channel 已关闭 @@ -184,7 +184,7 @@ func ExampleRecoverTransform() { > 执行 f 函数,如果 f 为 nil,则不执行 *** -#### func HandleV(v V, f func (v V)) +#### func HandleV\[V any\](v V, f func (v V)) > 执行 f 函数,如果 f 为 nil,则不执行 @@ -194,7 +194,7 @@ func ExampleRecoverTransform() { > go 代码格式化 *** -#### func If(expression bool, t T, f T) T +#### func If\[T any\](expression bool, t T, f T) T *** @@ -230,7 +230,7 @@ func ExampleRecoverTransform() { > 开始损耗计数 *** -#### func Match(value Value) *Matcher[Value, Result] +#### func Match\[Value any, Result any\](value Value) *Matcher[Value, Result] > 匹配 @@ -450,7 +450,7 @@ func TestNumberToRome(t *testing.T) { > 切片转换为字符串 *** -#### func NewPermission() *Permission[Code, EntityID] +#### func NewPermission\[Code generic.Integer, EntityID comparable\]() *Permission[Code, EntityID] > 创建权限 @@ -562,7 +562,7 @@ func TestNewPermission(t *testing.T) { > 以零拷贝的方式将字节切片转换为字符串 *** -#### func Convert(src A) B +#### func Convert\[A any, B any\](src A) B > 以零拷贝的方式将一个对象转换为另一个对象 > - 两个对象字段必须完全一致 @@ -591,7 +591,7 @@ func TestConvert(t *testing.T) { *** -#### func Verify(handle func ( V)) *VerifyHandle[V] +#### func Verify\[V any\](handle func ( V)) *VerifyHandle[V] > 对特定表达式进行校验,当表达式不成立时,将执行 handle diff --git a/utils/times/README.md b/utils/times/README.md index dc2a35e..033d92f 100644 --- a/utils/times/README.md +++ b/utils/times/README.md @@ -250,7 +250,7 @@ func ExampleCalcNextSecWithTime() { > 获取一个时间的年末 *** -#### func NewStateLine(zero State) *StateLine[State] +#### func NewStateLine\[State generic.Basic\](zero State) *StateLine[State] > 创建一个从左向右由早到晚的状态时间线