Documentation
¶
Overview ¶
Package permute implements a generic method for in-place generation of all permutations for ordered collections.
Example (CustomType) ¶
package main
import (
"fmt"
"github.com/cespare/permute"
)
type ByteSlice []byte
func (s ByteSlice) Len() int { return len(s) }
func (s ByteSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func main() {
b := []byte{'A', 'B', 'C'}
p := permute.New(ByteSlice(b))
for p.Permute() {
fmt.Println(string(b))
}
}
Output: ABC BAC CAB ACB BCA CBA
Example (Ints) ¶
package main
import (
"fmt"
"github.com/cespare/permute"
)
func main() {
s := []int{5, 7}
p := permute.Ints(s)
for p.Permute() {
fmt.Println(s)
}
}
Output: [5 7] [7 5]
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Interface ¶
type Interface interface {
// Len is the number of elements in the collection.
Len() int
// Swap swaps the elements with indexes i and j.
Swap(i, j int)
}
Interface is satisfied by types (usually ordered collections) which can have all permutations generated by a Permuter.
type Permuter ¶
type Permuter struct {
// contains filtered or unexported fields
}
A Permuter holds state about an ongoing iteration of permutations.
Click to show internal directories.
Click to hide internal directories.