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 ¶
IsInvalidConfig asserts invalidConfigError.
func IsMaxGrowthReached ¶
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.
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.