Documentation ¶
Overview ¶
Package shuffle provides mechanisms for permuting data.
Index ¶
- type FisherYates
- func (f *FisherYates) Grow(delta uint32)
- func (f *FisherYates) GrowTo(n uint32)
- func (f *FisherYates) Permutation() []int
- func (f *FisherYates) Permute(n uint32, rng Rand) ([]int, error)
- func (f *FisherYates) PermuteUpTo(n uint32, rng Rand) []int
- func (f *FisherYates) Remaining() uint32
- func (f *FisherYates) Size() int
- type Rand
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FisherYates ¶
type FisherYates struct {
// contains filtered or unexported fields
}
FisherYates implements a Fisher–Yates shuffle with an extendable pool size.
func NewFisherYates ¶
func NewFisherYates(n uint32) *FisherYates
NewFisherYates returns a new FisherYates with a specified pool size.
func (*FisherYates) Grow ¶
func (f *FisherYates) Grow(delta uint32)
Grow increases the size of the pool of values from which Permute can choose. It doesn't change already-permuted values in any way, and simply appends the next n indices to those available to future calls to Permute.
func (*FisherYates) GrowTo ¶
func (f *FisherYates) GrowTo(n uint32)
GrowTo is equivalent to f.Grow(max(0, f.Size()-n)); i.e. it grows the size of the pool to n, unless it is already greater than or equal to this size.
func (*FisherYates) Permutation ¶
func (f *FisherYates) Permutation() []int
Permutation returns the already-permuted values.
func (*FisherYates) Permute ¶
func (f *FisherYates) Permute(n uint32, rng Rand) ([]int, error)
Permute chooses up to n values from the pool, limited by the number of already-permuted values.
func (*FisherYates) PermuteUpTo ¶
func (f *FisherYates) PermuteUpTo(n uint32, rng Rand) []int
PermuteUpTo is equivalent to Permute(min(n, f.Remaining())).
func (*FisherYates) Remaining ¶
func (f *FisherYates) Remaining() uint32
Remaining returns the number of unshuffled values in the pool; i.e. the difference between Size() and the sum of all n passed to Permute().
func (*FisherYates) Size ¶
func (f *FisherYates) Size() int
Size returns the size of the pool from which Permute() chooses the next indices. It is the sum of the values passed to NewFisherYates() and all calls to Grow().