docs: 优化 README.md 包级函数不显示泛型签名的情况

This commit is contained in:
kercylan98 2024-01-15 10:54:27 +08:00
parent e7e679ea86
commit a026e4cf96
40 changed files with 389 additions and 377 deletions

View File

@ -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
<span id="LoadOrRefreshActivity"></span>
> 加载或刷新活动
> - 通常在活动配置刷新时候将活动通过该方法注册或刷新
***
#### 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]
<span id="DefineNoneDataActivity"></span>
> 声明无数据的活动类型
***
#### 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]
<span id="DefineGlobalDataActivity"></span>
> 声明拥有全局数据的活动类型
***
#### 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]
<span id="DefineEntityDataActivity"></span>
> 声明拥有实体数据的活动类型
***
#### 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]
<span id="DefineGlobalAndEntityDataActivity"></span>
> 声明拥有全局数据和实体数据的活动类型
***
#### func RegUpcomingEvent(activityType Type, handler UpcomingEventHandler[ID], priority ...int)
#### func RegUpcomingEvent\[Type generic.Basic, ID generic.Basic\](activityType Type, handler UpcomingEventHandler[ID], priority ...int)
<span id="RegUpcomingEvent"></span>
> 注册即将开始的活动事件处理器
***
#### func OnUpcomingEvent(activity *Activity[Type, ID])
#### func OnUpcomingEvent\[Type generic.Basic, ID generic.Basic\](activity *Activity[Type, ID])
<span id="OnUpcomingEvent"></span>
> 即将开始的活动事件
***
#### func RegStartedEvent(activityType Type, handler StartedEventHandler[ID], priority ...int)
#### func RegStartedEvent\[Type generic.Basic, ID generic.Basic\](activityType Type, handler StartedEventHandler[ID], priority ...int)
<span id="RegStartedEvent"></span>
> 注册活动开始事件处理器
***
#### func OnStartedEvent(activity *Activity[Type, ID])
#### func OnStartedEvent\[Type generic.Basic, ID generic.Basic\](activity *Activity[Type, ID])
<span id="OnStartedEvent"></span>
> 活动开始事件
***
#### func RegEndedEvent(activityType Type, handler EndedEventHandler[ID], priority ...int)
#### func RegEndedEvent\[Type generic.Basic, ID generic.Basic\](activityType Type, handler EndedEventHandler[ID], priority ...int)
<span id="RegEndedEvent"></span>
> 注册活动结束事件处理器
***
#### func OnEndedEvent(activity *Activity[Type, ID])
#### func OnEndedEvent\[Type generic.Basic, ID generic.Basic\](activity *Activity[Type, ID])
<span id="OnEndedEvent"></span>
> 活动结束事件
***
#### func RegExtendedShowStartedEvent(activityType Type, handler ExtendedShowStartedEventHandler[ID], priority ...int)
#### func RegExtendedShowStartedEvent\[Type generic.Basic, ID generic.Basic\](activityType Type, handler ExtendedShowStartedEventHandler[ID], priority ...int)
<span id="RegExtendedShowStartedEvent"></span>
> 注册活动结束后延长展示开始事件处理器
***
#### func OnExtendedShowStartedEvent(activity *Activity[Type, ID])
#### func OnExtendedShowStartedEvent\[Type generic.Basic, ID generic.Basic\](activity *Activity[Type, ID])
<span id="OnExtendedShowStartedEvent"></span>
> 活动结束后延长展示开始事件
***
#### func RegExtendedShowEndedEvent(activityType Type, handler ExtendedShowEndedEventHandler[ID], priority ...int)
#### func RegExtendedShowEndedEvent\[Type generic.Basic, ID generic.Basic\](activityType Type, handler ExtendedShowEndedEventHandler[ID], priority ...int)
<span id="RegExtendedShowEndedEvent"></span>
> 注册活动结束后延长展示结束事件处理器
***
#### func OnExtendedShowEndedEvent(activity *Activity[Type, ID])
#### func OnExtendedShowEndedEvent\[Type generic.Basic, ID generic.Basic\](activity *Activity[Type, ID])
<span id="OnExtendedShowEndedEvent"></span>
> 活动结束后延长展示结束事件
***
#### func RegNewDayEvent(activityType Type, handler NewDayEventHandler[ID], priority ...int)
#### func RegNewDayEvent\[Type generic.Basic, ID generic.Basic\](activityType Type, handler NewDayEventHandler[ID], priority ...int)
<span id="RegNewDayEvent"></span>
> 注册新的一天事件处理器
***
#### func OnNewDayEvent(activity *Activity[Type, ID])
#### func OnNewDayEvent\[Type generic.Basic, ID generic.Basic\](activity *Activity[Type, ID])
<span id="OnNewDayEvent"></span>
> 新的一天事件

View File

@ -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]
<span id="NewTurnBased"></span>
> 创建一个新的回合制
> - calcNextTurnDuration 将返回下一次行动时间间隔,适用于按照速度计算下一次行动时间间隔的情况。当返回 0 时,将使用默认的行动超时时间

View File

@ -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]
<span id="NewRoomManager"></span>
> 创建房间管理器 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]
<span id="NewRoomControllerOptions"></span>
> 创建房间控制器选项

View File

@ -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])
<span id="RegisterRefreshTaskCounterEvent"></span>
> 注册特定任务类型的刷新任务计数器事件处理函数
@ -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])
<span id="RegisterRefreshTaskConditionEvent"></span>
> 注册特定任务类型的刷新任务条件事件处理函数

View File

@ -138,7 +138,7 @@ func TestNewBot(t *testing.T) {
<span id="DefaultWebsocketUpgrader"></span>
***
#### func NewHttpHandleWrapper(srv *Server, packer ContextPacker[Context]) *Http[Context]
#### func NewHttpHandleWrapper\[Context any\](srv *Server, packer ContextPacker[Context]) *Http[Context]
<span id="NewHttpHandleWrapper"></span>
> 创建一个新的 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]
<span id="NewGinWrapper"></span>
> 创建 gin 包装器,用于对 NewHttpWrapper 函数的替代

View File

@ -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]
<span id="NewDispatcher"></span>
> 创建一个新的消息分发器 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]
<span id="NewManager"></span>
> 生成消息分发器管理器

View File

@ -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]
<span id="NewLockstep"></span>
> 创建一个锁步(帧)同步默认实现的组件(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]
<span id="WithFrameLimit"></span>
> 通过特定逻辑帧上限创建锁步(帧)同步组件
> - 当达到上限时将停止广播
***
#### func WithFrameRate(frameRate int64) Option[ClientID, Command]
#### func WithFrameRate\[ClientID comparable, Command any\](frameRate int64) Option[ClientID, Command]
<span id="WithFrameRate"></span>
> 通过特定逻辑帧率创建锁步(帧)同步组件
> - 默认情况下为 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]
<span id="WithSerialization"></span>
> 通过特定的序列化方式将每一帧的数据进行序列化
>
@ -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]
<span id="WithInitFrame"></span>
> 通过特定的初始帧创建锁步(帧)同步组件
> - 默认情况下为 0即第一帧索引为 0

View File

@ -33,7 +33,7 @@
***
## 详情信息
#### func NewMultistage(options ...MultistageOption[HandleFunc]) *Multistage[HandleFunc]
#### func NewMultistage\[HandleFunc any\](options ...MultistageOption[HandleFunc]) *Multistage[HandleFunc]
<span id="NewMultistage"></span>
> 创建一个支持多级分类的路由器
@ -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]
<span id="WithRouteTrim"></span>
> 路由修剪选项
> - 将在路由注册前对路由进行对应处理

View File

@ -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]
<span id="NewChannel"></span>
> 创建基于 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]
<span id="NewUnbounded"></span>
> 创建写循环
> - pool 用于管理 Message 对象的缓冲池,在创建 Message 对象时也应该使用该缓冲池,以便复用 Message 对象。 Unbounded 会在写入完成后将 Message 对象放回缓冲池

View File

@ -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]
<span id="NewTwoDimensional"></span>
<details>

View File

@ -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]
<span id="WithAreaConstraint"></span>
> 设置编排区域的约束条件
> - 该约束用于判断一个成员是否可以被添加到该编排区域中
> - 与 WithAreaConflict 不同的是,约束通常用于非成员关系导致的硬性约束,例如:成员的等级过滤、成员的性别等
***
#### func WithAreaConflict(conflict AreaConflictHandle[ID, AreaInfo]) AreaOption[ID, AreaInfo]
#### func WithAreaConflict\[ID comparable, AreaInfo any\](conflict AreaConflictHandle[ID, AreaInfo]) AreaOption[ID, AreaInfo]
<span id="WithAreaConflict"></span>
> 设置编排区域的冲突条件,冲突处理函数需要返回造成冲突的成员列表
> - 该冲突用于判断一个成员是否可以被添加到该编排区域中
> - 与 WithAreaConstraint 不同的是,冲突通常用于成员关系导致的软性约束,例如:成员的职业唯一性、成员的种族唯一性等
***
#### func WithAreaEvaluate(evaluate AreaEvaluateHandle[ID, AreaInfo]) AreaOption[ID, AreaInfo]
#### func WithAreaEvaluate\[ID comparable, AreaInfo any\](evaluate AreaEvaluateHandle[ID, AreaInfo]) AreaOption[ID, AreaInfo]
<span id="WithAreaEvaluate"></span>
> 设置编排区域的评估函数
> - 该评估函数将影响成员被编入区域的优先级
***
#### func NewArrangement(options ...Option[ID, AreaInfo]) *Arrangement[ID, AreaInfo]
#### func NewArrangement\[ID comparable, AreaInfo any\](options ...Option[ID, AreaInfo]) *Arrangement[ID, AreaInfo]
<span id="NewArrangement"></span>
> 创建一个新的编排
***
#### func WithItemFixed(matcher ItemFixedAreaHandle[AreaInfo]) ItemOption[ID, AreaInfo]
#### func WithItemFixed\[ID comparable, AreaInfo any\](matcher ItemFixedAreaHandle[AreaInfo]) ItemOption[ID, AreaInfo]
<span id="WithItemFixed"></span>
> 设置成员的固定编排区域
***
#### func WithItemPriority(priority ItemPriorityHandle[ID, AreaInfo]) ItemOption[ID, AreaInfo]
#### func WithItemPriority\[ID comparable, AreaInfo any\](priority ItemPriorityHandle[ID, AreaInfo]) ItemOption[ID, AreaInfo]
<span id="WithItemPriority"></span>
> 设置成员的优先级
***
#### func WithItemNotAllow(verify ItemNotAllowVerifyHandle[ID, AreaInfo]) ItemOption[ID, AreaInfo]
#### func WithItemNotAllow\[ID comparable, AreaInfo any\](verify ItemNotAllowVerifyHandle[ID, AreaInfo]) ItemOption[ID, AreaInfo]
<span id="WithItemNotAllow"></span>
> 设置成员不允许的编排区域
***
#### func WithRetryThreshold(threshold int) Option[ID, AreaInfo]
#### func WithRetryThreshold\[ID comparable, AreaInfo any\](threshold int) Option[ID, AreaInfo]
<span id="WithRetryThreshold"></span>
> 设置编排时的重试阈值
> - 当每一轮编排结束任有成员未被编排时,将会进行下一轮编排,直到编排次数达到该阈值
> - 默认的阈值为 10 次
***
#### func WithConstraintHandle(handle ConstraintHandle[ID, AreaInfo]) Option[ID, AreaInfo]
#### func WithConstraintHandle\[ID comparable, AreaInfo any\](handle ConstraintHandle[ID, AreaInfo]) Option[ID, AreaInfo]
<span id="WithConstraintHandle"></span>
> 设置编排时触发约束时的处理函数
> - 当约束条件触发时,将会调用该函数。如果无法在该函数中处理约束,应该继续返回 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]
<span id="WithConflictHandle"></span>
> 设置编排时触发冲突时的处理函数
> - 当冲突条件触发时,将会调用该函数。如果无法在该函数中处理冲突,应该继续返回这一批成员,尝试进行下一层的冲突处理

View File

@ -40,7 +40,7 @@ buffer 提供了缓冲区相关的实用程序。
***
## 详情信息
#### func NewRing(initSize ...int) *Ring[T]
#### func NewRing\[T any\](initSize ...int) *Ring[T]
<span id="NewRing"></span>
> 创建一个并发不安全的环形缓冲区
> - initSize: 初始容量
@ -68,12 +68,12 @@ func TestNewRing(t *testing.T) {
***
#### func NewRingUnbounded(bufferSize int) *RingUnbounded[T]
#### func NewRingUnbounded\[T any\](bufferSize int) *RingUnbounded[T]
<span id="NewRingUnbounded"></span>
> 创建一个并发安全的基于环形缓冲区实现的无界缓冲区
***
#### func NewUnbounded() *Unbounded[V]
#### func NewUnbounded\[V any\]() *Unbounded[V]
<span id="NewUnbounded"></span>
> 创建一个无界缓冲区
> - generateNil: 生成空值的函数,该函数仅需始终返回 nil 即可

View File

@ -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
<span id="CloneSlice"></span>
> 克隆切片,该函数是 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
<span id="CloneMap"></span>
> 克隆 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
<span id="CloneSliceN"></span>
> 克隆 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
<span id="CloneMapN"></span>
> 克隆 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
<span id="CloneSlices"></span>
> 克隆多个切片
@ -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
<span id="CloneMaps"></span>
> 克隆多个 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
<span id="InSlice"></span>
> 检查 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
<span id="InComparableSlice"></span>
> 检查 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
<span id="AllInSlice"></span>
> 检查 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
<span id="AllInComparableSlice"></span>
> 检查 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
<span id="AnyInSlice"></span>
> 检查 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
<span id="AnyInComparableSlice"></span>
> 检查 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
<span id="InSlices"></span>
> 通过将多个切片合并后检查 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
<span id="InComparableSlices"></span>
> 通过将多个切片合并后检查 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
<span id="AllInSlices"></span>
> 通过将多个切片合并后检查 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
<span id="AllInComparableSlices"></span>
> 通过将多个切片合并后检查 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
<span id="AnyInSlices"></span>
> 通过将多个切片合并后检查 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
<span id="AnyInComparableSlices"></span>
> 通过将多个切片合并后检查 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
<span id="InAllSlices"></span>
> 检查 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
<span id="InAllComparableSlices"></span>
> 检查 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
<span id="AnyInAllSlices"></span>
> 检查 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
<span id="AnyInAllComparableSlices"></span>
> 检查 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
<span id="KeyInMap"></span>
> 检查 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
<span id="ValueInMap"></span>
> 检查 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
<span id="AllKeyInMap"></span>
> 检查 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
<span id="AllValueInMap"></span>
> 检查 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
<span id="AnyKeyInMap"></span>
> 检查 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
<span id="AnyValueInMap"></span>
> 检查 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
<span id="AllKeyInMaps"></span>
> 检查 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
<span id="AllValueInMaps"></span>
> 检查 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
<span id="AnyKeyInMaps"></span>
> 检查 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
<span id="AnyValueInMaps"></span>
> 检查 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
<span id="KeyInAllMaps"></span>
> 检查 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
<span id="AnyKeyInAllMaps"></span>
> 检查 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
<span id="ConvertSliceToAny"></span>
> 将切片转换为任意类型的切片
@ -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
<span id="ConvertSliceToIndexMap"></span>
> 将切片转换为索引为键的映射
@ -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 {}
<span id="ConvertSliceToIndexOnlyMap"></span>
> 将切片转换为索引为键的映射
@ -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 {}
<span id="ConvertSliceToMap"></span>
> 将切片转换为值为键的映射
@ -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
<span id="ConvertSliceToBoolMap"></span>
> 将切片转换为值为键的映射
@ -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
<span id="ConvertMapKeysToSlice"></span>
> 将映射的键转换为切片
@ -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
<span id="ConvertMapValuesToSlice"></span>
> 将映射的值转换为切片
@ -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
<span id="InvertMap"></span>
> 将映射的键和值互换
@ -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
<span id="ConvertMapValuesToBool"></span>
> 将映射的值转换为布尔值
@ -2217,7 +2218,7 @@ func TestConvertMapValuesToBool(t *testing.T) {
***
#### func ReverseSlice(s *S)
#### func ReverseSlice\[S ~[]V, V any\](s *S)
<span id="ReverseSlice"></span>
> 将切片反转
@ -2270,7 +2271,7 @@ func TestReverseSlice(t *testing.T) {
***
#### func ClearSlice(slice *S)
#### func ClearSlice\[S ~[]V, V any\](slice *S)
<span id="ClearSlice"></span>
> 清空切片
@ -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)
<span id="ClearMap"></span>
> 清空 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)
<span id="DropSliceByIndices"></span>
> 删除切片中特定索引的元素
@ -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)
<span id="DropSliceByCondition"></span>
> 删除切片中符合条件的元素
> - 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])
<span id="DropSliceOverlappingElements"></span>
> 删除切片中与另一个切片重叠的元素
@ -2542,7 +2543,7 @@ func TestDropSliceOverlappingElements(t *testing.T) {
***
#### func DeduplicateSliceInPlace(s *S)
#### func DeduplicateSliceInPlace\[S ~[]V, V comparable\](s *S)
<span id="DeduplicateSliceInPlace"></span>
> 去除切片中的重复元素
@ -2592,7 +2593,7 @@ func TestDeduplicateSliceInPlace(t *testing.T) {
***
#### func DeduplicateSlice(s S) S
#### func DeduplicateSlice\[S ~[]V, V comparable\](s S) S
<span id="DeduplicateSlice"></span>
> 去除切片中的重复元素,返回新切片
@ -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)
<span id="DeduplicateSliceInPlaceWithCompare"></span>
> 去除切片中的重复元素,使用自定义的比较函数
@ -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
<span id="DeduplicateSliceWithCompare"></span>
> 去除切片中的重复元素,使用自定义的比较函数,返回新的切片
@ -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
<span id="FilterOutByIndices"></span>
> 过滤切片中特定索引的元素,返回过滤后的切片
@ -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
<span id="FilterOutByCondition"></span>
> 过滤切片中符合条件的元素,返回过滤后的切片
> - 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
<span id="FilterOutByKey"></span>
> 过滤 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
<span id="FilterOutByValue"></span>
> 过滤 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
<span id="FilterOutByKeys"></span>
> 过滤 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
<span id="FilterOutByValues"></span>
> 过滤 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
<span id="FilterOutByMap"></span>
> 过滤 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)
<span id="FindLoopedNextInSlice"></span>
> 返回 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)
<span id="FindLoopedPrevInSlice"></span>
> 返回 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
<span id="FindCombinationsInSliceByRange"></span>
> 获取给定数组的所有组合,且每个组合的成员数量限制在指定范围内
@ -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
<span id="FindFirstOrDefaultInSlice"></span>
> 判断切片中是否存在元素,返回第一个元素,不存在则返回默认值
@ -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)
<span id="FindOrDefaultInSlice"></span>
> 判断切片中是否存在某个元素,返回第一个匹配的索引和元素,不存在则返回默认值
@ -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)
<span id="FindOrDefaultInComparableSlice"></span>
> 判断切片中是否存在某个元素,返回第一个匹配的索引和元素,不存在则返回默认值
@ -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)
<span id="FindInSlice"></span>
> 判断切片中是否存在某个元素,返回第一个匹配的索引和元素,不存在则索引返回 -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
<span id="FindIndexInSlice"></span>
> 判断切片中是否存在某个元素,返回第一个匹配的索引,不存在则索引返回 -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)
<span id="FindInComparableSlice"></span>
> 判断切片中是否存在某个元素,返回第一个匹配的索引和元素,不存在则索引返回 -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
<span id="FindIndexInComparableSlice"></span>
> 判断切片中是否存在某个元素,返回第一个匹配的索引,不存在则索引返回 -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)
<span id="FindMinimumInComparableSlice"></span>
> 获取切片中的最小值
@ -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)
<span id="FindMinimumInSlice"></span>
> 获取切片中的最小值
@ -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)
<span id="FindMaximumInComparableSlice"></span>
> 获取切片中的最大值
@ -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)
<span id="FindMaximumInSlice"></span>
> 获取切片中的最大值
@ -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)
<span id="FindMin2MaxInComparableSlice"></span>
> 获取切片中的最小值和最大值
@ -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)
<span id="FindMin2MaxInSlice"></span>
> 获取切片中的最小值和最大值
@ -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)
<span id="FindMinFromComparableMap"></span>
> 获取 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)
<span id="FindMinFromMap"></span>
> 获取 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)
<span id="FindMaxFromComparableMap"></span>
> 获取 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)
<span id="FindMaxFromMap"></span>
> 获取 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)
<span id="FindMin2MaxFromComparableMap"></span>
> 获取 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)
<span id="FindMin2MaxFromMap"></span>
> 获取 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)
<span id="SwapSlice"></span>
> 将切片中的两个元素进行交换
@ -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
<span id="MappingFromSlice"></span>
> 将切片中的元素进行转换
@ -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
<span id="MappingFromMap"></span>
> 将 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)
<span id="MergeSlices"></span>
> 合并切片
@ -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)
<span id="MergeMaps"></span>
> 合并 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)
<span id="MergeMapsWithSkip"></span>
> 合并 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)
<span id="ChooseRandomSliceElementRepeatN"></span>
> 返回 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)
<span id="ChooseRandomIndexRepeatN"></span>
> 返回 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)
<span id="ChooseRandomSliceElement"></span>
> 返回 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)
<span id="ChooseRandomIndex"></span>
> 返回 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)
<span id="ChooseRandomSliceElementN"></span>
> 返回 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)
<span id="ChooseRandomIndexN"></span>
> 获取切片中的 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)
<span id="ChooseRandomMapKeyRepeatN"></span>
> 获取 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)
<span id="ChooseRandomMapValueRepeatN"></span>
> 获取 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
<span id="ChooseRandomMapKeyAndValueRepeatN"></span>
> 获取 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)
<span id="ChooseRandomMapKey"></span>
> 获取 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)
<span id="ChooseRandomMapValue"></span>
> 获取 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)
<span id="ChooseRandomMapKeyN"></span>
> 获取 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)
<span id="ChooseRandomMapValueN"></span>
> 获取 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)
<span id="ChooseRandomMapKeyAndValue"></span>
> 获取 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
<span id="ChooseRandomMapKeyAndValueN"></span>
> 获取 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
<span id="DescBy"></span>
> 返回降序比较结果
@ -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
<span id="AscBy"></span>
> 返回升序比较结果
@ -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)
<span id="Desc"></span>
> 对切片进行降序排序
@ -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
<span id="DescByClone"></span>
> 对切片进行降序排序,返回排序后的切片
@ -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)
<span id="Asc"></span>
> 对切片进行升序排序
@ -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
<span id="AscByClone"></span>
> 对切片进行升序排序,返回排序后的切片
@ -5323,7 +5324,7 @@ func TestAscByClone(t *testing.T) {
***
#### func Shuffle(slice *S)
#### func Shuffle\[S ~[]V, V any\](slice *S)
<span id="Shuffle"></span>
> 对切片进行随机排序
@ -5367,7 +5368,7 @@ func TestShuffle(t *testing.T) {
***
#### func ShuffleByClone(slice S) S
#### func ShuffleByClone\[S ~[]V, V any\](slice S) S
<span id="ShuffleByClone"></span>
> 对切片进行随机排序,返回排序后的切片

View File

@ -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

View File

@ -1,2 +1,2 @@
// Package collection 用于对 input 和 map 操作的工具函数
// Package collection 定义了各种对于集合操作有用的各种函数
package collection

View File

@ -36,22 +36,22 @@
***
## 详情信息
#### func NewMatrix(dimensions ...int) *Matrix[V]
#### func NewMatrix\[V any\](dimensions ...int) *Matrix[V]
<span id="NewMatrix"></span>
> 创建一个新的 Matrix 实例。
***
#### func NewPagedSlice(pageSize int) *PagedSlice[T]
#### func NewPagedSlice\[T any\](pageSize int) *PagedSlice[T]
<span id="NewPagedSlice"></span>
> 创建一个新的 PagedSlice 实例。
***
#### func NewPrioritySlice(lengthAndCap ...int) *PrioritySlice[V]
#### func NewPrioritySlice\[V any\](lengthAndCap ...int) *PrioritySlice[V]
<span id="NewPrioritySlice"></span>
> 创建一个优先级切片
***
#### func NewSyncSlice(length int, cap int) *SyncSlice[V]
#### func NewSyncSlice\[V any\](length int, cap int) *SyncSlice[V]
<span id="NewSyncSlice"></span>
> 创建一个 SyncSlice

View File

@ -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]
<span id="NewSyncMap"></span>
> 创建一个 SyncMap

View File

@ -65,12 +65,12 @@ combination 包提供了一些实用的组合函数。
***
## 详情信息
#### func NewCombination(options ...Option[T]) *Combination[T]
#### func NewCombination\[T Item\](options ...Option[T]) *Combination[T]
<span id="NewCombination"></span>
> 创建一个新的组合器
***
#### func WithEvaluation(evaluate func (items []T) float64) Option[T]
#### func WithEvaluation\[T Item\](evaluate func (items []T) float64) Option[T]
<span id="WithEvaluation"></span>
> 设置组合评估函数
> - 用于对组合进行评估,返回一个分值的评价函数
@ -79,57 +79,57 @@ combination 包提供了一些实用的组合函数。
> - 默认的评估函数将返回一个随机数
***
#### func NewMatcher(options ...MatcherOption[T]) *Matcher[T]
#### func NewMatcher\[T Item\](options ...MatcherOption[T]) *Matcher[T]
<span id="NewMatcher"></span>
> 创建一个新的匹配器
***
#### func WithMatcherEvaluation(evaluate func (items []T) float64) MatcherOption[T]
#### func WithMatcherEvaluation\[T Item\](evaluate func (items []T) float64) MatcherOption[T]
<span id="WithMatcherEvaluation"></span>
> 设置匹配器评估函数
> - 用于对组合进行评估,返回一个分值的评价函数
> - 通过该选项将覆盖匹配器的默认(WithEvaluation)评估函数
***
#### func WithMatcherLeastLength(length int) MatcherOption[T]
#### func WithMatcherLeastLength\[T Item\](length int) MatcherOption[T]
<span id="WithMatcherLeastLength"></span>
> 通过匹配最小长度的组合创建匹配器
> - length: 组合的长度,表示需要匹配的组合最小数量
***
#### func WithMatcherLength(length int) MatcherOption[T]
#### func WithMatcherLength\[T Item\](length int) MatcherOption[T]
<span id="WithMatcherLength"></span>
> 通过匹配长度的组合创建匹配器
> - length: 组合的长度,表示需要匹配的组合数量
***
#### func WithMatcherMostLength(length int) MatcherOption[T]
#### func WithMatcherMostLength\[T Item\](length int) MatcherOption[T]
<span id="WithMatcherMostLength"></span>
> 通过匹配最大长度的组合创建匹配器
> - length: 组合的长度,表示需要匹配的组合最大数量
***
#### func WithMatcherIntervalLength(min int, max int) MatcherOption[T]
#### func WithMatcherIntervalLength\[T Item\](min int, max int) MatcherOption[T]
<span id="WithMatcherIntervalLength"></span>
> 通过匹配长度区间的组合创建匹配器
> - 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]
<span id="WithMatcherContinuity"></span>
> 通过匹配连续的组合创建匹配器
> - 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]
<span id="WithMatcherSame"></span>
> 通过匹配相同的组合创建匹配器
> - 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]
<span id="WithMatcherNCarryM"></span>
> 通过匹配 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]
<span id="WithMatcherNCarryIndependentM"></span>
> 通过匹配 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]
<span id="NewValidator"></span>
> 创建一个新的校验器
***
#### func WithValidatorHandle(handle func (items []T) bool) ValidatorOption[T]
#### func WithValidatorHandle\[T Item\](handle func (items []T) bool) ValidatorOption[T]
<span id="WithValidatorHandle"></span>
> 通过特定的验证函数对组合进行验证
***
#### func WithValidatorHandleLength(length int) ValidatorOption[T]
#### func WithValidatorHandleLength\[T Item\](length int) ValidatorOption[T]
<span id="WithValidatorHandleLength"></span>
> 校验组合的长度是否符合要求
***
#### func WithValidatorHandleLengthRange(min int, max int) ValidatorOption[T]
#### func WithValidatorHandleLengthRange\[T Item\](min int, max int) ValidatorOption[T]
<span id="WithValidatorHandleLengthRange"></span>
> 校验组合的长度是否在指定的范围内
***
#### func WithValidatorHandleLengthMin(min int) ValidatorOption[T]
#### func WithValidatorHandleLengthMin\[T Item\](min int) ValidatorOption[T]
<span id="WithValidatorHandleLengthMin"></span>
> 校验组合的长度是否大于等于指定的最小值
***
#### func WithValidatorHandleLengthMax(max int) ValidatorOption[T]
#### func WithValidatorHandleLengthMax\[T Item\](max int) ValidatorOption[T]
<span id="WithValidatorHandleLengthMax"></span>
> 校验组合的长度是否小于等于指定的最大值
***
#### func WithValidatorHandleLengthNot(length int) ValidatorOption[T]
#### func WithValidatorHandleLengthNot\[T Item\](length int) ValidatorOption[T]
<span id="WithValidatorHandleLengthNot"></span>
> 校验组合的长度是否不等于指定的值
***
#### 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]
<span id="WithValidatorHandleTypeLength"></span>
> 校验组合成员类型数量是否为指定的值
***
#### 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]
<span id="WithValidatorHandleTypeLengthRange"></span>
> 校验组合成员类型数量是否在指定的范围内
***
#### 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]
<span id="WithValidatorHandleTypeLengthMin"></span>
> 校验组合成员类型数量是否大于等于指定的最小值
***
#### 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]
<span id="WithValidatorHandleTypeLengthMax"></span>
> 校验组合成员类型数量是否小于等于指定的最大值
***
#### 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]
<span id="WithValidatorHandleTypeLengthNot"></span>
> 校验组合成员类型数量是否不等于指定的值
***
#### func WithValidatorHandleContinuous(getIndex func (item T) Index) ValidatorOption[T]
#### func WithValidatorHandleContinuous\[T Item, Index generic.Integer\](getIndex func (item T) Index) ValidatorOption[T]
<span id="WithValidatorHandleContinuous"></span>
> 校验组合成员是否连续
***
#### func WithValidatorHandleContinuousNot(getIndex func (item T) Index) ValidatorOption[T]
#### func WithValidatorHandleContinuousNot\[T Item, Index generic.Integer\](getIndex func (item T) Index) ValidatorOption[T]
<span id="WithValidatorHandleContinuousNot"></span>
> 校验组合成员是否不连续
***
#### 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]
<span id="WithValidatorHandleGroupContinuous"></span>
> 校验组合成员是否能够按类型分组并且连续
***
#### 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]
<span id="WithValidatorHandleGroupContinuousN"></span>
> 校验组合成员是否能够按分组为 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]
<span id="WithValidatorHandleNCarryM"></span>
> 校验组合成员是否匹配 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]
<span id="WithValidatorHandleNCarryIndependentM"></span>
> 校验组合成员是否匹配 N 携带独立的 M 的组合
> - n: 组合中元素的数量表示需要匹配的组合数量n 的类型需要全部相同

View File

@ -33,12 +33,12 @@ deck 包中的内容用于针对一堆内容的管理,适用但不限于牌堆
***
## 详情信息
#### func NewDeck() *Deck[I]
#### func NewDeck\[I Item\]() *Deck[I]
<span id="NewDeck"></span>
> 创建一个新的甲板
***
#### func NewGroup(guid int64, fillHandle func (guid int64) []I) *Group[I]
#### func NewGroup\[I Item\](guid int64, fillHandle func (guid int64) []I) *Group[I]
<span id="NewGroup"></span>
> 创建一个新的组

View File

@ -36,34 +36,34 @@
***
## 详情信息
#### func NewFSM(data Data) *FSM[State, Data]
#### func NewFSM\[State comparable, Data any\](data Data) *FSM[State, Data]
<span id="NewFSM"></span>
> 创建一个新的状态机
***
#### 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]
<span id="WithEnterBeforeEvent"></span>
> 设置状态进入前的回调
> - 在首次设置状态时,状态机本身的当前状态为零值状态
***
#### 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]
<span id="WithEnterAfterEvent"></span>
> 设置状态进入后的回调
***
#### 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]
<span id="WithUpdateEvent"></span>
> 设置状态内刷新的回调
***
#### 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]
<span id="WithExitBeforeEvent"></span>
> 设置状态退出前的回调
> - 该阶段状态机的状态为退出前的状态,而非新的状态
***
#### 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]
<span id="WithExitAfterEvent"></span>
> 设置状态退出后的回调
> - 该阶段状态机的状态为新的状态,而非退出前的状态

View File

@ -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")
}

View File

@ -48,17 +48,17 @@ generic 目的在于提供一组基于泛型的用于处理通用功能的函数
***
## 详情信息
#### func IsNil(v V) bool
#### func IsNil\[V any\](v V) bool
<span id="IsNil"></span>
> 检查指定的值是否为 nil
***
#### func IsAllNil(v ...V) bool
#### func IsAllNil\[V any\](v ...V) bool
<span id="IsAllNil"></span>
> 检查指定的值是否全部为 nil
***
#### func IsHasNil(v ...V) bool
#### func IsHasNil\[V any\](v ...V) bool
<span id="IsHasNil"></span>
> 检查指定的值是否存在 nil

View File

@ -132,7 +132,7 @@ geometry 旨在提供一组用于处理几何形状和计算几何属性的函
***
## 详情信息
#### func NewCircle(radius V, points int) Circle[V]
#### func NewCircle\[V generic.SignedNumber\](radius V, points int) Circle[V]
<span id="NewCircle"></span>
> 通过传入圆的半径和需要的点数量,生成一个圆
@ -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
<span id="CalcCircleCentroidDistance"></span>
> 计算两个圆质心距离
@ -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)
<span id="GetDirectionNextWithCoordinate"></span>
> 获取特定方向上的下一个坐标
***
#### func GetDirectionNextWithPoint(direction Direction, point Point[V]) Point[V]
#### func GetDirectionNextWithPoint\[V generic.SignedNumber\](direction Direction, point Point[V]) Point[V]
<span id="GetDirectionNextWithPoint"></span>
> 获取特定方向上的下一个坐标
***
#### func GetDirectionNextWithPos(direction Direction, width V, pos V) V
#### func GetDirectionNextWithPos\[V generic.SignedNumber\](direction Direction, width V, pos V) V
<span id="GetDirectionNextWithPos"></span>
> 获取位置在特定宽度和特定方向上的下一个位置
> - 需要注意的是,在左右方向时,当下一个位置不在矩形区域内时,将会返回上一行的末位置或下一行的首位置
***
#### 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
<span id="CalcDirection"></span>
> 计算点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
<span id="CalcDistanceWithCoordinate"></span>
> 计算两点之间的距离
***
#### func CalcDistanceWithPoint(point1 Point[V], point2 Point[V]) V
#### func CalcDistanceWithPoint\[V generic.SignedNumber\](point1 Point[V], point2 Point[V]) V
<span id="CalcDistanceWithPoint"></span>
> 计算两点之间的距离
***
#### 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
<span id="CalcDistanceSquared"></span>
> 计算两点之间的平方距离
> - 这个函数的主要用途是在需要计算两点之间距离的情况下,但不需要得到实际的距离值,而只需要比较距离大小。因为平方根运算相对较为耗时,所以在只需要比较大小的情况下,通常会使用平方距离。
***
#### 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
<span id="CalcAngle"></span>
> 计算点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)
<span id="CalcNewCoordinate"></span>
> 根据给定的x、y坐标、角度和距离计算新的坐标
***
#### func CalcRadianWithAngle(angle V) V
#### func CalcRadianWithAngle\[V generic.SignedNumber\](angle V) V
<span id="CalcRadianWithAngle"></span>
> 根据角度 angle 计算弧度
***
#### func CalcAngleDifference(angleA V, angleB V) V
#### func CalcAngleDifference\[V generic.SignedNumber\](angleA V, angleB V) V
<span id="CalcAngleDifference"></span>
> 计算两个角度之间的最小角度差
***
#### 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
<span id="CalcRayIsIntersect"></span>
> 根据给定的位置和角度生成射线,检测射线是否与多边形发生碰撞
***
#### func NewLineSegment(start Point[V], end Point[V]) LineSegment[V]
#### func NewLineSegment\[V generic.SignedNumber\](start Point[V], end Point[V]) LineSegment[V]
<span id="NewLineSegment"></span>
> 创建一根线段
***
#### 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]
<span id="NewLineSegmentCap"></span>
> 创建一根包含数据的线段
***
#### 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]
<span id="NewLineSegmentCapWithLine"></span>
> 通过已有线段创建一根包含数据的线段
***
#### func ConvertLineSegmentGeneric(line LineSegment[V]) LineSegment[TO]
#### func ConvertLineSegmentGeneric\[V generic.SignedNumber, TO generic.SignedNumber\](line LineSegment[V]) LineSegment[TO]
<span id="ConvertLineSegmentGeneric"></span>
> 转换线段的泛型类型为特定类型
***
#### 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
<span id="PointOnLineSegmentWithCoordinate"></span>
> 通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上
***
#### 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
<span id="PointOnLineSegmentWithPos"></span>
> 通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上
***
#### 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
<span id="PointOnLineSegmentWithPoint"></span>
> 通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上
***
#### 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
<span id="PointOnLineSegmentWithCoordinateInBounds"></span>
> 通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上
> - 与 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
<span id="PointOnLineSegmentWithPosInBounds"></span>
> 通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上
> - 与 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
<span id="PointOnLineSegmentWithPointInBounds"></span>
> 通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上
> - 与 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
<span id="CalcLineSegmentIsCollinear"></span>
> 检查两条线段在一个误差内是否共线
> - 共线是指两条线段在同一直线上,即它们的延长线可以重合
***
#### 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)
<span id="CalcLineSegmentIsOverlap"></span>
> 通过对点进行排序来检查两条共线线段是否重叠,返回重叠线段
***
#### func CalcLineSegmentIsIntersect(line1 LineSegment[V], line2 LineSegment[V]) bool
#### func CalcLineSegmentIsIntersect\[V generic.SignedNumber\](line1 LineSegment[V], line2 LineSegment[V]) bool
<span id="CalcLineSegmentIsIntersect"></span>
> 计算两条线段是否相交
@ -305,17 +305,17 @@ func TestCalcLineSegmentIsIntersect(t *testing.T) {
***
#### func CalcLineSegmentSlope(line LineSegment[V]) V
#### func CalcLineSegmentSlope\[V generic.SignedNumber\](line LineSegment[V]) V
<span id="CalcLineSegmentSlope"></span>
> 计算线段的斜率
***
#### func CalcLineSegmentIntercept(line LineSegment[V]) V
#### func CalcLineSegmentIntercept\[V generic.SignedNumber\](line LineSegment[V]) V
<span id="CalcLineSegmentIntercept"></span>
> 计算线段的截距
***
#### func NewPoint(x V, y V) Point[V]
#### func NewPoint\[V generic.SignedNumber\](x V, y V) Point[V]
<span id="NewPoint"></span>
> 创建一个由 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]
<span id="NewPointCap"></span>
> 创建一个由 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]
<span id="NewPointCapWithData"></span>
> 通过设置数据的方式创建一个由 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]
<span id="NewPointCapWithPoint"></span>
> 通过设置数据的方式创建一个由已有坐标组成的点,这个点具有一个数据容量
***
#### func CoordinateToPoint(x V, y V) Point[V]
#### func CoordinateToPoint\[V generic.SignedNumber\](x V, y V) Point[V]
<span id="CoordinateToPoint"></span>
> 将坐标转换为x、y的坐标数组
***
#### func CoordinateToPos(width V, x V, y V) V
#### func CoordinateToPos\[V generic.SignedNumber\](width V, x V, y V) V
<span id="CoordinateToPos"></span>
> 将坐标转换为二维数组的顺序位置坐标
> - 需要确保x的取值范围必须小于width或者将会得到不正确的值
***
#### func PointToCoordinate(position Point[V]) (x V, y V)
#### func PointToCoordinate\[V generic.SignedNumber\](position Point[V]) (x V, y V)
<span id="PointToCoordinate"></span>
> 将坐标数组转换为x和y坐标
***
#### func PointToPos(width V, xy Point[V]) V
#### func PointToPos\[V generic.SignedNumber\](width V, xy Point[V]) V
<span id="PointToPos"></span>
> 将坐标转换为二维数组的顺序位置
> - 需要确保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)
<span id="PosToCoordinate"></span>
> 通过宽度将一个二维数组的顺序位置转换为xy坐标
***
#### func PosToPoint(width V, pos V) Point[V]
#### func PosToPoint\[V generic.SignedNumber\](width V, pos V) Point[V]
<span id="PosToPoint"></span>
> 通过宽度将一个二维数组的顺序位置转换为x、y的坐标数组
***
#### func PosToCoordinateX(width V, pos V) V
#### func PosToCoordinateX\[V generic.SignedNumber\](width V, pos V) V
<span id="PosToCoordinateX"></span>
> 通过宽度将一个二维数组的顺序位置转换为X坐标
***
#### func PosToCoordinateY(width V, pos V) V
#### func PosToCoordinateY\[V generic.SignedNumber\](width V, pos V) V
<span id="PosToCoordinateY"></span>
> 通过宽度将一个二维数组的顺序位置转换为Y坐标
***
#### func PointCopy(point Point[V]) Point[V]
#### func PointCopy\[V generic.SignedNumber\](point Point[V]) Point[V]
<span id="PointCopy"></span>
> 复制一个坐标数组
***
#### func PointToPosWithMulti(width V, points ...Point[V]) []V
#### func PointToPosWithMulti\[V generic.SignedNumber\](width V, points ...Point[V]) []V
<span id="PointToPosWithMulti"></span>
> 将一组坐标转换为二维数组的顺序位置
> - 需要确保x的取值范围必须小于width或者将会得到不正确的值
***
#### func PosToPointWithMulti(width V, positions ...V) []Point[V]
#### func PosToPointWithMulti\[V generic.SignedNumber\](width V, positions ...V) []Point[V]
<span id="PosToPointWithMulti"></span>
> 将一组二维数组的顺序位置转换为一组数组坐标
***
#### func PosSameRow(width V, pos1 V, pos2 V) bool
#### func PosSameRow\[V generic.SignedNumber\](width V, pos1 V, pos2 V) bool
<span id="PosSameRow"></span>
> 返回两个顺序位置在同一宽度是否位于同一行
***
#### 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)
<span id="DoublePointToCoordinate"></span>
> 将两个位置转换为 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]
<span id="CalcProjectionPoint"></span>
> 计算一个点到一条线段的最近点(即投影点)的。这个函数接收一个点和一条线段作为输入,线段由两个端点组成。
> - 该函数的主要用于需要计算一个点到一条线段的最近点的情况下
***
#### 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)
<span id="GetAdjacentTranslatePos"></span>
> 获取一个连续位置的矩阵中,特定位置相邻的最多四个平移方向(上下左右)的位置
***
#### 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])
<span id="GetAdjacentTranslateCoordinateXY"></span>
> 获取一个基于 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])
<span id="GetAdjacentTranslateCoordinateYX"></span>
> 获取一个基于 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)
<span id="GetAdjacentDiagonalsPos"></span>
> 获取一个连续位置的矩阵中,特定位置相邻的对角线最多四个方向的位置
***
#### 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])
<span id="GetAdjacentDiagonalsCoordinateXY"></span>
> 获取一个基于 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])
<span id="GetAdjacentDiagonalsCoordinateYX"></span>
> 获取一个基于 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)
<span id="GetAdjacentPos"></span>
> 获取一个连续位置的矩阵中,特定位置相邻的最多八个方向的位置
***
#### 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])
<span id="GetAdjacentCoordinateXY"></span>
> 获取一个基于 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])
<span id="GetAdjacentCoordinateYX"></span>
> 获取一个基于 yx 的二维矩阵中,特定位置相邻的最多八个方向的位置
***
#### func CoordinateMatrixToPosMatrix(matrix [][]V) (width int, posMatrix []V)
#### func CoordinateMatrixToPosMatrix\[V any\](matrix [][]V) (width int, posMatrix []V)
<span id="CoordinateMatrixToPosMatrix"></span>
> 将二维矩阵转换为顺序的二维矩阵
***
#### 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)
<span id="GetShapeCoverageAreaWithPoint"></span>
> 通过传入的一组坐标 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)
<span id="GetShapeCoverageAreaWithPos"></span>
> 通过传入的一组坐标 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)
<span id="CoverageAreaBoundless"></span>
> 将一个图形覆盖矩形范围设置为无边的
> - 无边化表示会将多余的部分进行裁剪,例如图形左边从 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])
<span id="GenerateShapeOnRectangle"></span>
> 生成一组二维坐标的形状
> - 这个形状将被在一个刚好能容纳形状的矩形中表示
@ -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)
<span id="GenerateShapeOnRectangleWithCoordinate"></span>
> 生成一组二维坐标的形状
> - 这个形状将被在一个刚好能容纳形状的矩形中表示
> - 为 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])
<span id="GetExpressibleRectangleBySize"></span>
> 获取一个宽高可表达的所有特定尺寸以上的矩形形状
> - 返回值表示了每一个矩形右下角的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])
<span id="GetExpressibleRectangle"></span>
> 获取一个宽高可表达的所有矩形形状
> - 返回值表示了每一个矩形右下角的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])
<span id="GetRectangleFullPointsByXY"></span>
> 通过开始结束坐标获取一个矩形包含的所有点
> - 例如 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])
<span id="GetRectangleFullPoints"></span>
> 获取一个矩形填充满后包含的所有点
***
#### func GetRectangleFullPos(width V, height V) (result []V)
#### func GetRectangleFullPos\[V generic.SignedNumber\](width V, height V) (result []V)
<span id="GetRectangleFullPos"></span>
> 获取一个矩形填充满后包含的所有位置
***
#### func CalcRectangleCentroid(shape Shape[V]) Point[V]
#### func CalcRectangleCentroid\[V generic.SignedNumber\](shape Shape[V]) Point[V]
<span id="CalcRectangleCentroid"></span>
> 计算矩形质心
> - 非多边形质心计算,仅为顶点的平均值 - 该区域中多边形因子的适当质心
@ -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]
<span id="NewShape"></span>
> 通过多个点生成一个形状进行返回
@ -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])
<span id="NewShapeWithString"></span>
> 通过字符串将指定 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
<span id="CalcBoundingRadius"></span>
> 计算多边形转换为圆的半径
***
#### func CalcBoundingRadiusWithCentroid(shape Shape[V], centroid Point[V]) V
#### func CalcBoundingRadiusWithCentroid\[V generic.SignedNumber\](shape Shape[V], centroid Point[V]) V
<span id="CalcBoundingRadiusWithCentroid"></span>
> 计算多边形在特定质心下圆的半径
***
#### 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
<span id="CalcTriangleTwiceArea"></span>
> 计算由 a、b、c 三个点组成的三角形的面积的两倍
***
#### func IsPointOnEdge(edges []LineSegment[V], point Point[V]) bool
#### func IsPointOnEdge\[V generic.SignedNumber\](edges []LineSegment[V], point Point[V]) bool
<span id="IsPointOnEdge"></span>
> 检查点是否在 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)
<span id="ProjectionPointToShape"></span>
> 将一个点投影到一个多边形上,找到离该点最近的投影点,并返回投影点和距离

View File

@ -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
<span id="Find"></span>
> 使用 A* 算法在导航网格上查找从起点到终点的最短路径,并返回路径上的节点序列。
>

View File

@ -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]
<span id="NewDistributionPattern"></span>
> 构建一个分布图实例

View File

@ -30,7 +30,7 @@ matrix 提供了一个简单的二维数组的实现
***
## 详情信息
#### func NewMatrix(width int, height int) *Matrix[T]
#### func NewMatrix\[T any\](width int, height int) *Matrix[T]
<span id="NewMatrix"></span>
> 生成特定宽高的二维矩阵
> - 虽然提供了通过x、y坐标的操作函数但是建议无论如何使用pos进行处理

View File

@ -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]
<span id="NewNavMesh"></span>
> 创建一个新的导航网格,并返回一个指向该导航网格的指针。
>

View File

@ -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]
<span id="NewObjectPool"></span>
> 创建一个 ObjectPool

View File

@ -34,7 +34,7 @@
***
## 详情信息
#### func NewFloat(x T) *Float
#### func NewFloat\[T generic.Number\](x T) *Float
<span id="NewFloat"></span>
> 创建一个 Float
@ -45,7 +45,7 @@
> - 如果字符串不是一个合法的数字,则返回 0
***
#### func NewInt(x T) *Int
#### func NewInt\[T generic.Number\](x T) *Int
<span id="NewInt"></span>
> 创建一个 Int

View File

@ -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]
<span id="NewBinarySearch"></span>
> 创建一个基于内存的二分查找排行榜
@ -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]
<span id="WithBinarySearchCount"></span>
> 通过限制排行榜竞争者数量来创建排行榜
> - 默认情况下允许100位竞争者
***
#### func WithBinarySearchASC() BinarySearchOption[CompetitorID, Score]
#### func WithBinarySearchASC\[CompetitorID comparable, Score generic.Ordered\]() BinarySearchOption[CompetitorID, Score]
<span id="WithBinarySearchASC"></span>
> 通过升序的方式创建排行榜
> - 默认情况下为降序

View File

@ -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
<span id="Int"></span>
> 构造一个带有整数值的字段
***
#### func IntP(key string, val *I) slog.Attr
#### func IntP\[I generic.Integer\](key string, val *I) slog.Attr
<span id="IntP"></span>
> 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"
***
#### func Int8(key string, val I) slog.Attr
#### func Int8\[I generic.Integer\](key string, val I) slog.Attr
<span id="Int8"></span>
> 构造一个带有整数值的字段
***
#### func Int8P(key string, val *I) slog.Attr
#### func Int8P\[I generic.Integer\](key string, val *I) slog.Attr
<span id="Int8P"></span>
> 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"
***
#### func Int16(key string, val I) slog.Attr
#### func Int16\[I generic.Integer\](key string, val I) slog.Attr
<span id="Int16"></span>
> 构造一个带有整数值的字段
***
#### func Int16P(key string, val *I) slog.Attr
#### func Int16P\[I generic.Integer\](key string, val *I) slog.Attr
<span id="Int16P"></span>
> 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"
***
#### func Int32(key string, val I) slog.Attr
#### func Int32\[I generic.Integer\](key string, val I) slog.Attr
<span id="Int32"></span>
> 构造一个带有整数值的字段
***
#### func Int32P(key string, val *I) slog.Attr
#### func Int32P\[I generic.Integer\](key string, val *I) slog.Attr
<span id="Int32P"></span>
> 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"
***
#### func Int64(key string, val I) slog.Attr
#### func Int64\[I generic.Integer\](key string, val I) slog.Attr
<span id="Int64"></span>
> 构造一个带有整数值的字段
***
#### func Int64P(key string, val *I) slog.Attr
#### func Int64P\[I generic.Integer\](key string, val *I) slog.Attr
<span id="Int64P"></span>
> 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"
***
#### func Uint(key string, val I) slog.Attr
#### func Uint\[I generic.Integer\](key string, val I) slog.Attr
<span id="Uint"></span>
> 构造一个带有整数值的字段
***
#### func UintP(key string, val *I) slog.Attr
#### func UintP\[I generic.Integer\](key string, val *I) slog.Attr
<span id="UintP"></span>
> 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"
***
#### func Uint8(key string, val I) slog.Attr
#### func Uint8\[I generic.Integer\](key string, val I) slog.Attr
<span id="Uint8"></span>
> 构造一个带有整数值的字段
***
#### func Uint8P(key string, val *I) slog.Attr
#### func Uint8P\[I generic.Integer\](key string, val *I) slog.Attr
<span id="Uint8P"></span>
> 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"
***
#### func Uint16(key string, val I) slog.Attr
#### func Uint16\[I generic.Integer\](key string, val I) slog.Attr
<span id="Uint16"></span>
> 构造一个带有整数值的字段
***
#### func Uint16P(key string, val *I) slog.Attr
#### func Uint16P\[I generic.Integer\](key string, val *I) slog.Attr
<span id="Uint16P"></span>
> 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"
***
#### func Uint32(key string, val I) slog.Attr
#### func Uint32\[I generic.Integer\](key string, val I) slog.Attr
<span id="Uint32"></span>
> 构造一个带有整数值的字段
***
#### func Uint32P(key string, val *I) slog.Attr
#### func Uint32P\[I generic.Integer\](key string, val *I) slog.Attr
<span id="Uint32P"></span>
> 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"
***
#### func Uint64(key string, val I) slog.Attr
#### func Uint64\[I generic.Integer\](key string, val I) slog.Attr
<span id="Uint64"></span>
> 构造一个带有整数值的字段
***
#### func Uint64P(key string, val *I) slog.Attr
#### func Uint64P\[I generic.Integer\](key string, val *I) slog.Attr
<span id="Uint64P"></span>
> 构造一个带有整数值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"
***
#### func Float(key string, val F) slog.Attr
#### func Float\[F generic.Float\](key string, val F) slog.Attr
<span id="Float"></span>
> 构造一个带有浮点值的字段
***
#### func FloatP(key string, val *F) slog.Attr
#### func FloatP\[F generic.Float\](key string, val *F) slog.Attr
<span id="FloatP"></span>
> 构造一个带有浮点值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"
***
#### func Float32(key string, val F) slog.Attr
#### func Float32\[F generic.Float\](key string, val F) slog.Attr
<span id="Float32"></span>
> 构造一个带有浮点值的字段
***
#### func Float32P(key string, val *F) slog.Attr
#### func Float32P\[F generic.Float\](key string, val *F) slog.Attr
<span id="Float32P"></span>
> 构造一个带有浮点值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"
***
#### func Float64(key string, val F) slog.Attr
#### func Float64\[F generic.Float\](key string, val F) slog.Attr
<span id="Float64"></span>
> 构造一个带有浮点值的字段
***
#### func Float64P(key string, val *F) slog.Attr
#### func Float64P\[F generic.Float\](key string, val *F) slog.Attr
<span id="Float64P"></span>
> 构造一个带有浮点值的字段。返回的 Field 将在适当的时候安全且显式地表示 "null"

View File

@ -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
<span id="Compare"></span>
> 根据特定表达式比较两个值
***
#### func IsContinuity(values S) bool
#### func IsContinuity\[S ~[]V, V generic.Integer\](values S) bool
<span id="IsContinuity"></span>
> 检查一组值是否连续
@ -72,7 +72,7 @@ func ExampleIsContinuity() {
```
***
#### func IsContinuityWithSort(values S) bool
#### func IsContinuityWithSort\[S ~[]V, V generic.Integer\](values S) bool
<span id="IsContinuityWithSort"></span>
> 检查一组值排序后是否连续
@ -92,57 +92,57 @@ func ExampleIsContinuity() {
> 整数幂运算
***
#### func Min(a V, b V) V
#### func Min\[V generic.Number\](a V, b V) V
<span id="Min"></span>
> 返回两个数之中较小的值
***
#### func Max(a V, b V) V
#### func Max\[V generic.Number\](a V, b V) V
<span id="Max"></span>
> 返回两个数之中较大的值
***
#### func MinMax(a V, b V) (min V, max V)
#### func MinMax\[V generic.Number\](a V, b V) (min V, max V)
<span id="MinMax"></span>
> 将两个数按照较小的和较大的顺序进行返回
***
#### func MaxMin(a V, b V) (max V, min V)
#### func MaxMin\[V generic.Number\](a V, b V) (max V, min V)
<span id="MaxMin"></span>
> 将两个数按照较大的和较小的顺序进行返回
***
#### func Clamp(value V, min V, max V) V
#### func Clamp\[V generic.Number\](value V, min V, max V) V
<span id="Clamp"></span>
> 将给定值限制在最小值和最大值之间
***
#### func Tolerance(value1 V, value2 V, tolerance V) bool
#### func Tolerance\[V generic.Number\](value1 V, value2 V, tolerance V) bool
<span id="Tolerance"></span>
> 检查两个值是否在一个误差范围内
***
#### func Merge(refer V, a V, b V) V
#### func Merge\[V generic.SignedNumber\](refer V, a V, b V) V
<span id="Merge"></span>
> 通过一个参考值合并两个数字
***
#### func UnMerge(refer V, num V) (a V, b V)
#### func UnMerge\[V generic.SignedNumber\](refer V, num V) (a V, b V)
<span id="UnMerge"></span>
> 通过一个参考值取消合并的两个数字
***
#### func MergeToInt64(v1 V, v2 V) int64
#### func MergeToInt64\[V generic.SignedNumber\](v1 V, v2 V) int64
<span id="MergeToInt64"></span>
> 将两个数字合并为一个 int64 数字
***
#### func UnMergeInt64(n int64) (V, V)
#### func UnMergeInt64\[V generic.SignedNumber\](n int64) (V, V)
<span id="UnMergeInt64"></span>
> 将一个 int64 数字拆分为两个数字
***
#### func ToContinuous(nums S) map[V]V
#### func ToContinuous\[S ~[]V, V generic.Integer\](nums S) map[V]V
<span id="ToContinuous"></span>
> 将一组非连续的数字转换为从1开始的连续数字
> - 返回值是一个 mapkey 是从 1 开始的连续数字value 是原始数字
@ -160,7 +160,7 @@ func ExampleToContinuous() {
```
***
#### func CountDigits(num V) int
#### func CountDigits\[V generic.Number\](num V) int
<span id="CountDigits"></span>
> 接收一个整数 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
<span id="JoinNumbers"></span>
> 将一组数字连接起来
***
#### func IsOdd(n V) bool
#### func IsOdd\[V generic.Integer\](n V) bool
<span id="IsOdd"></span>
> 返回 n 是否为奇数
***
#### func IsEven(n V) bool
#### func IsEven\[V generic.Integer\](n V) bool
<span id="IsEven"></span>
> 返回 n 是否为偶数
***
#### func MakeLastDigitsZero(num T, digits int) T
#### func MakeLastDigitsZero\[T generic.Number\](num T, digits int) T
<span id="MakeLastDigitsZero"></span>
> 返回一个新的数,其中 num 的最后 digits 位数被设为零。
> - 函数首先创建一个 10 的 digits 次方的遮罩,然后通过整除和乘以这个遮罩来使 num 的最后 digits 位归零。

View File

@ -38,7 +38,7 @@
> 运行持久化缓存程序
***
#### func BindPersistCacheProgram(name string, handler OutputParamHandlerFunc, option ...*Option) func ()
#### func BindPersistCacheProgram\[OutputParamHandlerFunc any\](name string, handler OutputParamHandlerFunc, option ...*Option) func ()
<span id="BindPersistCacheProgram"></span>
> 绑定持久化缓存程序
> - name 持久化缓存程序名称
@ -52,7 +52,7 @@
> - 所有持久化程序绑定完成后,应该主动调用 Run 函数运行
***
#### func BindAction(name string, handler Func) Func
#### func BindAction\[Func any\](name string, handler Func) Func
<span id="BindAction"></span>
> 绑定需要缓存的操作函数
> - name 缓存操作名称

View File

@ -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]
<span id="NewTwoDimensional"></span>
> 创建一个用于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]
<span id="WithTwoDimensionalTimeUnit"></span>
> 通过特定时间单位创建
> - 默认单位为1毫秒最小单位也为1毫秒
***
#### func WithTwoDimensionalIdleWaitTime(duration time.Duration) TwoDimensionalOption[EID, PosType]
#### func WithTwoDimensionalIdleWaitTime\[EID generic.Basic, PosType generic.SignedNumber\](duration time.Duration) TwoDimensionalOption[EID, PosType]
<span id="WithTwoDimensionalIdleWaitTime"></span>
> 通过特定的空闲等待时间创建
> - 默认情况下在没有新的移动计划时将限制 100毫秒 + 移动间隔事件(默认100毫秒)
***
#### func WithTwoDimensionalInterval(duration time.Duration) TwoDimensionalOption[EID, PosType]
#### func WithTwoDimensionalInterval\[EID generic.Basic, PosType generic.SignedNumber\](duration time.Duration) TwoDimensionalOption[EID, PosType]
<span id="WithTwoDimensionalInterval"></span>
> 通过特定的移动间隔时间创建

View File

@ -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)
<span id="ProbabilitySlice"></span>
> 按概率随机从切片中产生一个数据并返回命中的对象及是否未命中
> - 当总概率小于 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)
<span id="ProbabilitySliceIndex"></span>
> 按概率随机从切片中产生一个数据并返回命中的对象及对象索引以及是否未命中
> - 当总概率小于 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
<span id="WeightSlice"></span>
> 按权重随机从切片中产生一个数据并返回
***
#### 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)
<span id="WeightSliceIndex"></span>
> 按权重随机从切片中产生一个数据并返回数据和对应索引
***
#### 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
<span id="WeightMap"></span>
> 按权重随机从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)
<span id="WeightMapKey"></span>
> 按权重随机从map中产生一个数据并返回数据和对应 key

View File

@ -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)
<span id="WrapperFunc"></span>
> 包装函数
***
#### 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)
<span id="WrapperFuncBefore2After"></span>
> 包装函数,前置函数执行前,后置函数执行后
***
#### func WrapperFuncBefore(f Func, before func ()) (wf Func, err error)
#### func WrapperFuncBefore\[Func any\](f Func, before func ()) (wf Func, err error)
<span id="WrapperFuncBefore"></span>
> 包装函数,前置函数执行前
***
#### func WrapperFuncAfter(f Func, after func ()) (wf Func, err error)
#### func WrapperFuncAfter\[Func any\](f Func, after func ()) (wf Func, err error)
<span id="WrapperFuncAfter"></span>
> 包装函数,后置函数执行后
@ -67,7 +67,7 @@
> 拷贝
***
#### func GetPointer(src T) reflect.Value
#### func GetPointer\[T any\](src T) reflect.Value
<span id="GetPointer"></span>
> 获取指针

View File

@ -75,7 +75,7 @@
> 重置特定命名空间的唯一标识符
***
#### func NewOnce() *Once[V]
#### func NewOnce\[V any\]() *Once[V]
<span id="NewOnce"></span>
> 创建一个用于数据取值去重的结构实例

View File

@ -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)
<span id="Topological"></span>
> 拓扑排序是一种对有向图进行排序的算法,它可以用来解决一些依赖关系的问题,比如计算字段的依赖关系。拓扑排序会将存在依赖关系的元素进行排序,使得依赖关系的元素总是排在被依赖的元素之前。
> - slice: 需要排序的切片

View File

@ -104,18 +104,18 @@
***
## 详情信息
#### func NewBitSet(bits ...Bit) *BitSet[Bit]
#### func NewBitSet\[Bit generic.Integer\](bits ...Bit) *BitSet[Bit]
<span id="NewBitSet"></span>
> 通过指定的 Bit 位创建一个 BitSet
***
#### func TryWriteChannel(ch chan T, data T) bool
#### func TryWriteChannel\[T any\](ch chan T, data T) bool
<span id="TryWriteChannel"></span>
> 尝试写入 channel如果 channel 无法写入则忽略,返回是否写入成功
> - 无法写入的情况包括channel 已满、channel 已关闭
***
#### func TryWriteChannelByHandler(ch chan T, data T, handler func ())
#### func TryWriteChannelByHandler\[T any\](ch chan T, data T, handler func ())
<span id="TryWriteChannelByHandler"></span>
> 尝试写入 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))
<span id="HandleV"></span>
> 执行 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
<span id="If"></span>
***
@ -230,7 +230,7 @@ func ExampleRecoverTransform() {
> 开始损耗计数
***
#### func Match(value Value) *Matcher[Value, Result]
#### func Match\[Value any, Result any\](value Value) *Matcher[Value, Result]
<span id="Match"></span>
> 匹配
@ -450,7 +450,7 @@ func TestNumberToRome(t *testing.T) {
> 切片转换为字符串
***
#### func NewPermission() *Permission[Code, EntityID]
#### func NewPermission\[Code generic.Integer, EntityID comparable\]() *Permission[Code, EntityID]
<span id="NewPermission"></span>
> 创建权限
@ -562,7 +562,7 @@ func TestNewPermission(t *testing.T) {
> 以零拷贝的方式将字节切片转换为字符串
***
#### func Convert(src A) B
#### func Convert\[A any, B any\](src A) B
<span id="Convert"></span>
> 以零拷贝的方式将一个对象转换为另一个对象
> - 两个对象字段必须完全一致
@ -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]
<span id="Verify"></span>
> 对特定表达式进行校验,当表达式不成立时,将执行 handle

View File

@ -250,7 +250,7 @@ func ExampleCalcNextSecWithTime() {
> 获取一个时间的年末
***
#### func NewStateLine(zero State) *StateLine[State]
#### func NewStateLine\[State generic.Basic\](zero State) *StateLine[State]
<span id="NewStateLine"></span>
> 创建一个从左向右由早到晚的状态时间线