Documentation ¶
Overview ¶
Package arrangement 包提供了一些有用的函数来处理数组的排列。
更多的详细信息和使用示例,可以参考每个函数的文档。
Index ¶
- type Area
- func (slf *Area[ID, AreaInfo]) GetAreaInfo() AreaInfo
- func (slf *Area[ID, AreaInfo]) GetConflictItems(item Item[ID]) map[ID]Item[ID]
- func (slf *Area[ID, AreaInfo]) GetItems() map[ID]Item[ID]
- func (slf *Area[ID, AreaInfo]) GetScore(extra ...Item[ID]) float64
- func (slf *Area[ID, AreaInfo]) IsAllow(item Item[ID]) (constraintErr error, conflictItems map[ID]Item[ID], allow bool)
- func (slf *Area[ID, AreaInfo]) IsConflict(item Item[ID]) bool
- type AreaConflictHandle
- type AreaConstraintHandle
- type AreaEvaluateHandle
- type AreaOption
- func WithAreaConflict[ID comparable, AreaInfo any](conflict AreaConflictHandle[ID, AreaInfo]) AreaOption[ID, AreaInfo]
- func WithAreaConstraint[ID comparable, AreaInfo any](constraint AreaConstraintHandle[ID, AreaInfo]) AreaOption[ID, AreaInfo]
- func WithAreaEvaluate[ID comparable, AreaInfo any](evaluate AreaEvaluateHandle[ID, AreaInfo]) AreaOption[ID, AreaInfo]
- type Arrangement
- type ConflictHandle
- type ConstraintHandle
- type Editor
- func (slf *Editor[ID, AreaInfo]) AddAreaItem(area *Area[ID, AreaInfo], item Item[ID])
- func (slf *Editor[ID, AreaInfo]) GetAllowAreas(item Item[ID]) []*Area[ID, AreaInfo]
- func (slf *Editor[ID, AreaInfo]) GetAreas() []*Area[ID, AreaInfo]
- func (slf *Editor[ID, AreaInfo]) GetAreasWithScoreAsc(extra ...Item[ID]) []*Area[ID, AreaInfo]
- func (slf *Editor[ID, AreaInfo]) GetAreasWithScoreDesc(extra ...Item[ID]) []*Area[ID, AreaInfo]
- func (slf *Editor[ID, AreaInfo]) GetBestAllowArea(item Item[ID]) *Area[ID, AreaInfo]
- func (slf *Editor[ID, AreaInfo]) GetBestNoAllowArea(item Item[ID]) *Area[ID, AreaInfo]
- func (slf *Editor[ID, AreaInfo]) GetNoAllowAreas(item Item[ID]) []*Area[ID, AreaInfo]
- func (slf *Editor[ID, AreaInfo]) GetPendingCount() int
- func (slf *Editor[ID, AreaInfo]) GetRetryCount() int
- func (slf *Editor[ID, AreaInfo]) GetThresholdProgressRate() float64
- func (slf *Editor[ID, AreaInfo]) GetWorstAllowArea(item Item[ID]) *Area[ID, AreaInfo]
- func (slf *Editor[ID, AreaInfo]) GetWorstNoAllowArea(item Item[ID]) *Area[ID, AreaInfo]
- func (slf *Editor[ID, AreaInfo]) RemoveAreaItem(area *Area[ID, AreaInfo], item Item[ID])
- type Item
- type ItemFixedAreaHandle
- type ItemNotAllowVerifyHandle
- type ItemOption
- func WithItemFixed[ID comparable, AreaInfo any](matcher ItemFixedAreaHandle[AreaInfo]) ItemOption[ID, AreaInfo]
- func WithItemNotAllow[ID comparable, AreaInfo any](verify ItemNotAllowVerifyHandle[ID, AreaInfo]) ItemOption[ID, AreaInfo]
- func WithItemPriority[ID comparable, AreaInfo any](priority ItemPriorityHandle[ID, AreaInfo]) ItemOption[ID, AreaInfo]
- type ItemPriorityHandle
- type Option
- func WithConflictHandle[ID comparable, AreaInfo any](handle ConflictHandle[ID, AreaInfo]) Option[ID, AreaInfo]
- func WithConstraintHandle[ID comparable, AreaInfo any](handle ConstraintHandle[ID, AreaInfo]) Option[ID, AreaInfo]
- func WithRetryThreshold[ID comparable, AreaInfo any](threshold int) Option[ID, AreaInfo]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Area ¶
type Area[ID comparable, AreaInfo any] struct { // contains filtered or unexported fields }
Area 编排区域
func (*Area[ID, AreaInfo]) GetAreaInfo ¶
func (slf *Area[ID, AreaInfo]) GetAreaInfo() AreaInfo
GetAreaInfo 获取编排区域的信息
func (*Area[ID, AreaInfo]) GetConflictItems ¶ added in v0.0.26
GetConflictItems 获取与一个成员产生冲突的所有其他成员
func (*Area[ID, AreaInfo]) GetScore ¶
GetScore 获取该编排区域的评估分数
- 当 extra 不为空时,将会将 extra 中的内容添加到 items 中进行评估
func (*Area[ID, AreaInfo]) IsAllow ¶
func (slf *Area[ID, AreaInfo]) IsAllow(item Item[ID]) (constraintErr error, conflictItems map[ID]Item[ID], allow bool)
IsAllow 检测一个成员是否可以被添加到该编排区域中
func (*Area[ID, AreaInfo]) IsConflict ¶ added in v0.0.26
IsConflict 检测一个成员是否会造成冲突
type AreaConflictHandle ¶ added in v0.0.26
type AreaConflictHandle[ID comparable, AreaInfo any] func(area *Area[ID, AreaInfo], item Item[ID]) map[ID]Item[ID]
type AreaConstraintHandle ¶
type AreaConstraintHandle[ID comparable, AreaInfo any] func(area *Area[ID, AreaInfo], item Item[ID]) error
type AreaEvaluateHandle ¶
type AreaEvaluateHandle[ID comparable, AreaInfo any] func(areaInfo AreaInfo, items map[ID]Item[ID]) float64
type AreaOption ¶
type AreaOption[ID comparable, AreaInfo any] func(area *Area[ID, AreaInfo])
AreaOption 编排区域选项
func WithAreaConflict ¶ added in v0.0.26
func WithAreaConflict[ID comparable, AreaInfo any](conflict AreaConflictHandle[ID, AreaInfo]) AreaOption[ID, AreaInfo]
WithAreaConflict 设置编排区域的冲突条件,冲突处理函数需要返回造成冲突的成员列表
- 该冲突用于判断一个成员是否可以被添加到该编排区域中
- 与 WithAreaConstraint 不同的是,冲突通常用于成员关系导致的软性约束,例如:成员的职业唯一性、成员的种族唯一性等
func WithAreaConstraint ¶
func WithAreaConstraint[ID comparable, AreaInfo any](constraint AreaConstraintHandle[ID, AreaInfo]) AreaOption[ID, AreaInfo]
WithAreaConstraint 设置编排区域的约束条件
- 该约束用于判断一个成员是否可以被添加到该编排区域中
- 与 WithAreaConflict 不同的是,约束通常用于非成员关系导致的硬性约束,例如:成员的等级过滤、成员的性别等
func WithAreaEvaluate ¶
func WithAreaEvaluate[ID comparable, AreaInfo any](evaluate AreaEvaluateHandle[ID, AreaInfo]) AreaOption[ID, AreaInfo]
WithAreaEvaluate 设置编排区域的评估函数
- 该评估函数将影响成员被编入区域的优先级
type Arrangement ¶
type Arrangement[ID comparable, AreaInfo any] struct { // contains filtered or unexported fields }
Arrangement 用于针对多条数据进行合理编排的数据结构
- 我不知道这个数据结构的具体用途,但是我觉得这个数据结构应该是有用的
- 目前我能想到的用途只有我的过往经历:排课
- 如果是在游戏领域,或许适用于多人小队匹配编排等类似情况
func NewArrangement ¶
func NewArrangement[ID comparable, AreaInfo any](options ...Option[ID, AreaInfo]) *Arrangement[ID, AreaInfo]
NewArrangement 创建一个新的编排
func (*Arrangement[ID, AreaInfo]) AddArea ¶
func (slf *Arrangement[ID, AreaInfo]) AddArea(areaInfo AreaInfo, options ...AreaOption[ID, AreaInfo])
AddArea 添加一个编排区域
func (*Arrangement[ID, AreaInfo]) AddItem ¶
func (slf *Arrangement[ID, AreaInfo]) AddItem(item Item[ID])
AddItem 添加一个成员
func (*Arrangement[ID, AreaInfo]) Arrange ¶
func (slf *Arrangement[ID, AreaInfo]) Arrange() (areas []*Area[ID, AreaInfo], noSolution map[ID]Item[ID])
Arrange 编排
type ConflictHandle ¶ added in v0.0.26
type ConstraintHandle ¶ added in v0.0.26
type Editor ¶ added in v0.0.26
type Editor[ID comparable, AreaInfo any] struct { // contains filtered or unexported fields }
Editor 提供了大量辅助函数的编辑器
func (*Editor[ID, AreaInfo]) AddAreaItem ¶ added in v0.0.26
AddAreaItem 将一个成员添加到编排区域中,如果该成员已经存在于编排区域中,则不进行任何操作
func (*Editor[ID, AreaInfo]) GetAllowAreas ¶ added in v0.0.26
GetAllowAreas 获取允许的编排区域
func (*Editor[ID, AreaInfo]) GetAreasWithScoreAsc ¶ added in v0.0.26
GetAreasWithScoreAsc 获取所有的编排区域,并按照分数升序排序
func (*Editor[ID, AreaInfo]) GetAreasWithScoreDesc ¶ added in v0.0.26
GetAreasWithScoreDesc 获取所有的编排区域,并按照分数降序排序
func (*Editor[ID, AreaInfo]) GetBestAllowArea ¶ added in v0.0.26
GetBestAllowArea 获取最佳的允许的编排区域,如果不存在,则返回 nil
func (*Editor[ID, AreaInfo]) GetBestNoAllowArea ¶ added in v0.0.26
GetBestNoAllowArea 获取最佳的不允许的编排区域,如果不存在,则返回 nil
func (*Editor[ID, AreaInfo]) GetNoAllowAreas ¶ added in v0.0.26
GetNoAllowAreas 获取不允许的编排区域
func (*Editor[ID, AreaInfo]) GetPendingCount ¶ added in v0.0.26
GetPendingCount 获取待编排的成员数量
func (*Editor[ID, AreaInfo]) GetRetryCount ¶ added in v0.0.26
GetRetryCount 获取重试次数
func (*Editor[ID, AreaInfo]) GetThresholdProgressRate ¶ added in v0.0.26
GetThresholdProgressRate 获取重试次数阈值进度
func (*Editor[ID, AreaInfo]) GetWorstAllowArea ¶ added in v0.0.26
GetWorstAllowArea 获取最差的允许的编排区域,如果不存在,则返回 nil
func (*Editor[ID, AreaInfo]) GetWorstNoAllowArea ¶ added in v0.0.26
GetWorstNoAllowArea 获取最差的不允许的编排区域,如果不存在,则返回 nil
func (*Editor[ID, AreaInfo]) RemoveAreaItem ¶ added in v0.0.26
RemoveAreaItem 从编排区域中移除一个成员到待编排队列中,如果该成员不存在于编排区域中,则不进行任何操作
type Item ¶
type Item[ID comparable] interface { // GetID 获取成员的唯一标识 GetID() ID // Equal 比较两个成员是否相等 Equal(item Item[ID]) bool }
Item 编排成员
type ItemFixedAreaHandle ¶
type ItemNotAllowVerifyHandle ¶ added in v0.0.26
type ItemNotAllowVerifyHandle[ID comparable, AreaInfo any] func(areaInfo AreaInfo, item Item[ID]) bool
type ItemOption ¶
type ItemOption[ID comparable, AreaInfo any] func(arrangement *Arrangement[ID, AreaInfo], item Item[ID])
ItemOption 编排成员选项
func WithItemFixed ¶
func WithItemFixed[ID comparable, AreaInfo any](matcher ItemFixedAreaHandle[AreaInfo]) ItemOption[ID, AreaInfo]
WithItemFixed 设置成员的固定编排区域
func WithItemNotAllow ¶ added in v0.0.26
func WithItemNotAllow[ID comparable, AreaInfo any](verify ItemNotAllowVerifyHandle[ID, AreaInfo]) ItemOption[ID, AreaInfo]
WithItemNotAllow 设置成员不允许的编排区域
func WithItemPriority ¶
func WithItemPriority[ID comparable, AreaInfo any](priority ItemPriorityHandle[ID, AreaInfo]) ItemOption[ID, AreaInfo]
WithItemPriority 设置成员的优先级
type ItemPriorityHandle ¶
type ItemPriorityHandle[ID comparable, AreaInfo any] func(areaInfo AreaInfo, item Item[ID]) float64
type Option ¶
type Option[ID comparable, AreaInfo any] func(arrangement *Arrangement[ID, AreaInfo])
Option 编排选项
func WithConflictHandle ¶ added in v0.0.26
func WithConflictHandle[ID comparable, AreaInfo any](handle ConflictHandle[ID, AreaInfo]) Option[ID, AreaInfo]
WithConflictHandle 设置编排时触发冲突时的处理函数
- 当冲突条件触发时,将会调用该函数。如果无法在该函数中处理冲突,应该继续返回这一批成员,尝试进行下一层的冲突处理
- 当该函数的返回值长度为 0 时,表示冲突已经被处理,将会命中当前的编排区域
- 当所有的冲突处理函数都无法处理冲突时,将会进入下一个编排区域的尝试,如果均无法完成,将会将该成员加入到编排队列的末端,等待下一次编排
func WithConstraintHandle ¶ added in v0.0.26
func WithConstraintHandle[ID comparable, AreaInfo any](handle ConstraintHandle[ID, AreaInfo]) Option[ID, AreaInfo]
WithConstraintHandle 设置编排时触发约束时的处理函数
- 当约束条件触发时,将会调用该函数。如果无法在该函数中处理约束,应该继续返回 err,尝试进行下一层的约束处理
- 当该函数的返回值为 nil 时,表示约束已经被处理,将会命中当前的编排区域
- 当所有的约束处理函数都无法处理约束时,将会进入下一个编排区域的尝试,如果均无法完成,将会将该成员加入到编排队列的末端,等待下一次编排
有意思的是,硬性约束应该永远是无解的,而当需要进行一些打破规则的操作时,则可以透过该函数传入的 editor 进行操作
func WithRetryThreshold ¶ added in v0.0.26
func WithRetryThreshold[ID comparable, AreaInfo any](threshold int) Option[ID, AreaInfo]
WithRetryThreshold 设置编排时的重试阈值
- 当每一轮编排结束任有成员未被编排时,将会进行下一轮编排,直到编排次数达到该阈值
- 默认的阈值为 10 次