Skip to content

Commit

Permalink
other: 优化 combination 包命名,删除无用文件
Browse files Browse the repository at this point in the history
  • Loading branch information
kercylan98 committed Jul 29, 2023
1 parent 48d9c11 commit 57936b2
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion utils/combination/combination.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

// NewCombination 创建一个新的组合器
func NewCombination[T Item](options ...CombinationOption[T]) *Combination[T] {
func NewCombination[T Item](options ...Option[T]) *Combination[T] {
combination := &Combination[T]{
matchers: make(map[string]*Matcher[T]),
}
Expand Down
8 changes: 4 additions & 4 deletions utils/combination/combination_options.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package combination

// CombinationOption 组合器选项
type CombinationOption[T Item] func(*Combination[T])
// Option 组合器选项
type Option[T Item] func(*Combination[T])

// WithCombinationEvaluation 设置组合评估函数
// WithEvaluation 设置组合评估函数
// - 用于对组合进行评估,返回一个分值的评价函数
// - 通过该选项将设置所有匹配器的默认评估函数为该函数
// - 通过匹配器选项 WithMatcherEvaluation 可以覆盖该默认评估函数
// - 默认的评估函数将返回一个随机数
func WithCombinationEvaluation[T Item](evaluate func(items []T) float64) CombinationOption[T] {
func WithEvaluation[T Item](evaluate func(items []T) float64) Option[T] {
return func(c *Combination[T]) {
c.evaluate = evaluate
}
Expand Down
2 changes: 1 addition & 1 deletion utils/combination/combination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Poker struct {
}

func TestCombination_Best(t *testing.T) {
combine := combination.NewCombination(combination.WithCombinationEvaluation(func(items []*Poker) float64 {
combine := combination.NewCombination(combination.WithEvaluation(func(items []*Poker) float64 {
var total float64
for _, item := range items {
total += float64(item.Point)
Expand Down
1 change: 0 additions & 1 deletion utils/combination/filters.go

This file was deleted.

1 change: 1 addition & 0 deletions utils/combination/item.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package combination

type Item interface {
// 占位
}
2 changes: 1 addition & 1 deletion utils/combination/matcher_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type MatcherOption[T Item] func(matcher *Matcher[T])

// WithMatcherEvaluation 设置匹配器评估函数
// - 用于对组合进行评估,返回一个分值的评价函数
// - 通过该选项将覆盖匹配器的默认(WithCombinationEvaluation)评估函数
// - 通过该选项将覆盖匹配器的默认(WithEvaluation)评估函数
func WithMatcherEvaluation[T Item](evaluate func(items []T) float64) MatcherOption[T] {
return func(m *Matcher[T]) {
m.evaluate = evaluate
Expand Down

0 comments on commit 57936b2

Please sign in to comment.