balance

package
v0.0.0-...-7d8afc6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2022 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Items []Item `yaml:"items"`
}

type Item

type Item struct {
	Name   string `yaml:"name"`
	Weight int    `yaml:"weight"`
}

type Weight

type Weight interface {
	// Next gets next selected item.
	// Next is  goroutine-safe. You don't use the snchronization primitive to protect it in concurrent cases.
	Next() (item interface{})
	// Add adds a weighted item for selection. if adds an exit item ,weight  plussed
	Add(item interface{}, weight int)
	//All returns all items.
	All() map[interface{}]int

	// Reset resets the balancing algorithm.
	Reset()

	// RemoveAll removes all weighted items. Next will return nil if remove all
	RemoveAll()

	OnChange(c *Config)
}

Weight is a interface that implement a weighted round robin algorithm.

type WeightedRR

type WeightedRR struct {
	// contains filtered or unexported fields
}

WeightedRR ...

func NewWeightedRR

func NewWeightedRR(c *Config) *WeightedRR

func (*WeightedRR) Add

func (w *WeightedRR) Add(item interface{}, weight int)

func (*WeightedRR) All

func (w *WeightedRR) All() map[interface{}]int

func (*WeightedRR) Next

func (w *WeightedRR) Next() (item interface{})

Next ...

func (*WeightedRR) OnChange

func (w *WeightedRR) OnChange(c *Config)

func (*WeightedRR) RemoveAll

func (w *WeightedRR) RemoveAll()

func (*WeightedRR) Reset

func (w *WeightedRR) Reset()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL