Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BinarySearch ¶
BinarySearch searches for target in a sorted Slice and returns the position where target is found, or the position where target would appear in the sort order; it also returns a bool saying whether the target is really found in the Slice. The Slice must be sorted in increasing order.
func RandomChoose ¶
RandomChoose 根据权重数组随机选择一个元素
func RandomChooseFromTupleSlice ¶
RandomChooseFromTupleSlice 从随机数组中选择一个元素
Types ¶
type WeightRandomChoose ¶
type WeightRandomChoose[T any] struct { // 被带权重随机选择的目标数组 Slice []T // 权重数组 Weights []int // contains filtered or unexported fields }
WeightRandomChoose 带权重的随机选择,创建一个struct示例多次Random性能稍微好一些
func NewUseTupleSlice ¶
func NewUseTupleSlice[T any](tupleSlice []tuple.Tuple2[T, int]) (*WeightRandomChoose[T], error)
NewUseTupleSlice 从元组数组中创建
func (*WeightRandomChoose[T]) UpdateWeights ¶
func (x *WeightRandomChoose[T]) UpdateWeights(weights []int) error
UpdateWeights 更新权重数组,当权重有更改的时候不要直接修改Weights数组,而是通过这个方法更新权重
Click to show internal directories.
Click to hide internal directories.