permutation

package module
v0.0.0-...-1673c30 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2017 License: BSD-3-Clause Imports: 2 Imported by: 0

README

maturity build status code coverage GoDoc

permutation

The permutation package implements a service for simple permutations of arbitrary lists. The order of the members of a configured permutation list is permuted in a reproducible way.

Documentation

Overview

Package permutation provides a simple permutation service implementation in which the order of the members of a permutation list is permuted. Advantages of the permutation service is memory effiency and reproducability. It is memory efficient because all possible combinations are not stored in memory, but created on demand. Depending on the provided delta this can be quiet fast in case it is not too big. The service is reproducible because of the index used to represent a permutation.

Imagine the following example.

    []interface{"a", 7, []float64{2.88}}

This is how the initial service permutation looks like. In fact, there is
no permutation.

    []interface{}

This is how the first service permutation looks like.

    []interface{"a"}

This is how the second service permutation looks like.

    []interface{7}

This is how the third service permutation looks like.

    []interface{[]float64{2.88}}

This is how the Nth service permutation looks like.

    []interface{[]float64{2.88}, "a"}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsInvalidConfig

func IsInvalidConfig(err error) bool

IsInvalidConfig asserts invalidConfigError.

func IsMaxGrowthReached

func IsMaxGrowthReached(err error) bool

IsMaxGrowthReached asserts maxGrowthReachedError.

Types

type List

type List interface {
	// Indizes returns the list's current indizes.
	Indizes() []int
	// MaxGrowth returns the list's configured growth limit. The growth limit
	// is used to prevent infinite permutations. E.g. MaxGrowth set to 4 will not
	// permute up to a list of 5 raw values.
	MaxGrowth() int
	MinGrowth() int
	// PermutedValues returns the list's permuted values.
	PermutedValues() []interface{}
	// RawValues returns the list's unpermuted raw values.
	RawValues() []interface{}
	// SetIndizes sets the given indizes of the current permutation list.
	SetIndizes(indizes []int)
	SetMaxGrowth(maxGrowth int)
	SetMinGrowth(minGrowth int)
	SetRawValues(rawValues []interface{})
}

List is supposed to be permuted by a permutation service.

func NewList

func NewList(config ListConfig) (List, error)

NewList creates a new configured list.

type ListConfig

type ListConfig struct {
}

ListConfig represents the configuration used to create a new list.

func DefaultListConfig

func DefaultListConfig() ListConfig

DefaultListConfig provides a default configuration to create a new list by best effort.

type Service

type Service interface {
	// PermuteBy permutes the configured values by applying the given delta to
	// the currently configured indizes. Error might indicate that the configured
	// max growth is reached. It processes the essentiaal operation of permuting
	// the list's indizes using the given delta. Indizes are capped by the
	// amount of configured values. E.g. having a list of two values configured
	// will increment the indizes in a base 2 number system.
	//
	//     Imagine the following values being configured.
	//
	//         []interface{"a", "b"}
	//
	//     Here the index 0 translates to indizes []int{0} and causes the
	//     following permutation on the raw values.
	//
	//         []interface{"a"}
	//
	//     Here the index 1 translates to indizes []int{1} and causes the
	//     following permutation on the raw values.
	//
	//         []interface{"b"}
	//
	//     Here the index 00 translates to indizes []int{0, 0} and causes the
	//     following permutation on the raw values.
	//
	//         []interface{"a", "a"}
	//
	PermuteBy(list List, delta int) error
}

Service creates permutations of arbitrary lists as configured.

func NewService

func NewService(config ServiceConfig) (Service, error)

NewService creates a new configured service.

type ServiceConfig

type ServiceConfig struct {
}

ServiceConfig represents the configuration used to create a new service.

func DefaultServiceConfig

func DefaultServiceConfig() ServiceConfig

DefaultServiceConfig provides a default configuration to create a new service by best effort.

Jump to

Keyboard shortcuts

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