update selector

This commit is contained in:
ginuerzh
2022-09-04 13:24:32 +08:00
parent 05bfeb8a0f
commit a04c8b45f3
19 changed files with 97 additions and 81 deletions

View File

@ -3,22 +3,20 @@ package selector
import (
"math/rand"
"time"
"github.com/go-gost/core/selector"
)
type randomWeightedItem[T selector.Selectable] struct {
type randomWeightedItem[T any] struct {
item T
weight int
}
type randomWeighted[T selector.Selectable] struct {
type randomWeighted[T any] struct {
items []*randomWeightedItem[T]
sum int
r *rand.Rand
}
func newRandomWeighted[T selector.Selectable]() *randomWeighted[T] {
func newRandomWeighted[T any]() *randomWeighted[T] {
return &randomWeighted[T]{
r: rand.New(rand.NewSource(time.Now().UnixNano())),
}