utils

package
v0.0.0-...-0c26ca9 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2020 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecQueue

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

ExecQueue implements a queue that executes function calls in a single thread, in the same order as they have been queued.

func NewExecQueue

func NewExecQueue(capacity int) *ExecQueue

NewExecQueue creates a new execution Queue.

func (*ExecQueue) CanQueue

func (q *ExecQueue) CanQueue() bool

CanQueue returns true if more function calls can be added to the execution Queue.

func (*ExecQueue) Clear

func (q *ExecQueue) Clear()

Clear drops all queued functions.

func (*ExecQueue) Queue

func (q *ExecQueue) Queue(f func()) bool

Queue adds a function call to the execution Queue. Returns true if successful.

func (*ExecQueue) Quit

func (q *ExecQueue) Quit()

Quit stops the exec Queue.

Quit waits for the current execution to finish before returning.

type WeightedRandomSelect

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

WeightedRandomSelect is capable of weighted random selection from a set of items

func NewWeightedRandomSelect

func NewWeightedRandomSelect() *WeightedRandomSelect

NewWeightedRandomSelect returns a new WeightedRandomSelect structure

func (*WeightedRandomSelect) Choose

func (w *WeightedRandomSelect) Choose() wrsItem

Choose randomly selects an item from the set, with a chance proportional to its current weight. If the weight of the chosen element has been decreased since the last stored value, returns it with a newWeight/oldWeight chance, otherwise just updates its weight and selects another one

func (*WeightedRandomSelect) Remove

func (w *WeightedRandomSelect) Remove(item wrsItem)

Remove removes an item from the set

func (*WeightedRandomSelect) Update

func (w *WeightedRandomSelect) Update(item wrsItem)

Update updates an item's weight, adds it if it was non-existent or removes it if the new weight is zero. Note that explicitly updating decreasing weights is not necessary.

Jump to

Keyboard shortcuts

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