internal

package
v0.0.0-...-810b4b3 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosed  = errors.New("strpick: method called on closed picker")
	ErrEmpty   = errors.New("strpick: invalid Next on empty picker")
	ErrCorrupt = errors.New(
		"strpick: picker is in an invalid state, " +
			"do not use Unsafe from multiple goroutines")
	ErrOverflow = errors.New(
		"strpick: unrecoverable integer overflow, destroy and recreate the picker")
	ErrNegative = errors.New(
		"strpick: invalid negative number provided")
	ErrNaN                = errors.New("strpick: unexpected NaN")
	ErrInsufficientUnique = errors.New(
		"strpick: UniqueN called with N larger than Size()")
)

Functions

This section is empty.

Types

type Base

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

* The base implementation for all random string pickers.

Returns errors if it ever detects it has entered an inconsistent state as a result of concurrent access, but does not try to reliably detect misuse.

func NewBasePicker

func NewBasePicker() *Base

func NewLeftmostOldestBasePicker

func NewLeftmostOldestBasePicker() *Base

A Base picker that always returns the leftmost, oldest element For testing purposes only

func (*Base) Add

func (b *Base) Add(s string) (bool, int, error)

func (*Base) AddAll

func (b *Base) AddAll(ss []string) ([]bool, []int, error)

func (*Base) Close

func (b *Base) Close() error

func (*Base) Closed

func (b *Base) Closed() error

func (*Base) Contains

func (b *Base) Contains(s string) bool

func (*Base) GetBias

func (b *Base) GetBias() (float64, error)

Maybe this could be exposed as a method on Picker

func (*Base) GetRandomlyDistributeNewItems

func (b *Base) GetRandomlyDistributeNewItems() (bool, error)

Maybe this could be exposed as a method on Picker

func (*Base) Load

func (b *Base) Load(s string, g int) (bool, error)

For loading data from a database

func (*Base) LoadAll

func (b *Base) LoadAll(ss []string, g int) ([]bool, error)

func (*Base) LoadDB

func (b *Base) LoadDB(ss []string, gs []int) ([]bool, error)

Only gets called when loading values from a DB

func (*Base) MinGen

func (b *Base) MinGen() int

func (*Base) Next

func (b *Base) Next() (string, int, error)

Returns the new generation assigned to the string, not the old generation

func (*Base) NextN

func (b *Base) NextN(n int) ([]string, int, error)

func (*Base) Remove

func (b *Base) Remove(s string) (bool, error)

func (*Base) RemoveAll

func (b *Base) RemoveAll(ss []string) ([]bool, error)

func (*Base) SetBias

func (b *Base) SetBias(bi float64) error

func (*Base) SetRandomlyDistributeNewItems

func (b *Base) SetRandomlyDistributeNewItems(rand bool) error

func (*Base) Size

func (b *Base) Size() (int, error)

func (*Base) UniqueN

func (b *Base) UniqueN(n int) ([]string, int, error)

* Force unique values by removing items from the tree after selection.

Fails if n > Size().

func (*Base) Values

func (b *Base) Values() ([]string, error)

Jump to

Keyboard shortcuts

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