weighted

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RRW

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

func (*RRW) Add

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

func (*RRW) All

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

func (*RRW) Next

func (w *RRW) Next() interface{}
Example
w := &RRW{}
w.Add("a", 5)
w.Add("b", 2)
w.Add("c", 3)

for i := 0; i < 10; i++ {
	fmt.Printf("%s ", w.Next())
}
Output:

a a a c a b c a b c

func (*RRW) RemoveAll

func (w *RRW) RemoveAll()

func (*RRW) Reset

func (w *RRW) Reset()

type RandW

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

func NewRandW

func NewRandW() *RandW

func (*RandW) Add

func (rw *RandW) Add(item interface{}, weight int)

func (*RandW) All

func (rw *RandW) All() map[interface{}]int

func (*RandW) Next

func (rw *RandW) Next() (item interface{})
Example
w := NewRandW()
w.Add("a", 5)
w.Add("b", 2)
w.Add("c", 3)

for i := 0; i < 10; i++ {
	fmt.Printf("%s ", w.Next())
}
Output:

func (*RandW) RemoveAll

func (rw *RandW) RemoveAll()

func (*RandW) Reset

func (rw *RandW) Reset()

type SW

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

func NewSW

func NewSW() *SW

func (*SW) Add

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

func (*SW) All

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

func (*SW) Next

func (w *SW) Next() interface{}
Example
w := &SW{}
w.Add("a", 5)
w.Add("b", 2)
w.Add("c", 3)

for i := 0; i < 10; i++ {
	fmt.Printf("%s ", w.Next())
}
Output:

a c b a a c a b c a

func (*SW) RemoveAll

func (w *SW) RemoveAll()

func (*SW) Reset

func (w *SW) Reset()

type W

type W interface {

	// Next is not goroutine-safe. You MUST use the snchronization primitive to protect it in concurrent cases.
	Next() (item interface{})
	// Add adds a weighted item for selection.
	Add(item interface{}, weight int)

	// All returns all items.
	All() map[interface{}]int

	// RemoveAll removes all weighted items.
	RemoveAll()
	// Reset resets the balancing algorithm.
	Reset()
}

Jump to

Keyboard shortcuts

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