Documentation
¶
Index ¶
- type AddItemOption
- type AddItemOptions
- type NewOption
- type NewOptions
- type WeightSystem
- func (ws *WeightSystem[T]) AddItem(item T, opts ...AddItemOption)
- func (ws *WeightSystem[T]) AddItems(items []T, opts ...AddItemOption)
- func (ws *WeightSystem[T]) AdjustWeight(item T, success bool)
- func (ws *WeightSystem[T]) GetItem() T
- func (ws *WeightSystem[T]) MaxWeight() float64
- func (ws *WeightSystem[T]) MinWeight() float64
- func (ws *WeightSystem[T]) RemoveItem(item T)
- func (ws *WeightSystem[T]) SortedWeights() []WeightedItem[T]
- func (ws *WeightSystem[T]) Weights() map[T]float64
- type WeightedItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddItemOption ¶
type AddItemOption func(*AddItemOptions)
func WithWeight ¶
func WithWeight(weight float64) AddItemOption
type AddItemOptions ¶
type AddItemOptions struct {
// contains filtered or unexported fields
}
type NewOptions ¶
type NewOptions struct {
// contains filtered or unexported fields
}
type WeightSystem ¶
type WeightSystem[T comparable] struct { // contains filtered or unexported fields }
WeightSystem is a generic weight system for any comparable type T
func New ¶
func New[T comparable](opts ...NewOption) *WeightSystem[T]
New creates a new WeightSystem with the given items and weights Options can be passed to set the initial weight, min weight, and max weight If no options are passed, min weight will be 1, and max weight will be 1000
func (*WeightSystem[T]) AddItem ¶
func (ws *WeightSystem[T]) AddItem(item T, opts ...AddItemOption)
AddItem adds a new item to the system with the given weight
func (*WeightSystem[T]) AddItems ¶
func (ws *WeightSystem[T]) AddItems(items []T, opts ...AddItemOption)
AddItems adds multiple items to the system with the same weight
func (*WeightSystem[T]) AdjustWeight ¶
func (ws *WeightSystem[T]) AdjustWeight(item T, success bool)
AdjustWeight adjusts the weight of an item based on success or failure
func (*WeightSystem[T]) GetItem ¶
func (ws *WeightSystem[T]) GetItem() T
GetItem returns a randomly selected item based on weights
func (*WeightSystem[T]) MaxWeight ¶
func (ws *WeightSystem[T]) MaxWeight() float64
MaxWeight returns the maximum weight allowed in the system
func (*WeightSystem[T]) MinWeight ¶
func (ws *WeightSystem[T]) MinWeight() float64
MinWeight returns the minimum weight allowed in the system
func (*WeightSystem[T]) RemoveItem ¶
func (ws *WeightSystem[T]) RemoveItem(item T)
RemoveItem removes an item from the system
func (*WeightSystem[T]) SortedWeights ¶
func (ws *WeightSystem[T]) SortedWeights() []WeightedItem[T]
SortedWeights returns a sorted slice of WeightedItems, from highest weight to lowest
func (*WeightSystem[T]) Weights ¶
func (ws *WeightSystem[T]) Weights() map[T]float64
Weights returns a clone of the current weights map
type WeightedItem ¶
type WeightedItem[T comparable] struct { Item T Weight float64 }
WeightedItem represents an item with its associated weight