Documentation
¶
Overview ¶
Package permutation provides algorithms about permutations.
For better performance, all functions in this package are unsafe for concurrency unless otherwise specified.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NextPermutation ¶
NextPermutation transforms itf to its next permutation in lexical order. It returns false if itf.Len() == 0 or the permutations are exhausted, and true otherwise.
Time complexity: O(n), where n = itf.Len().
Types ¶
type Interface ¶
type Interface interface {
// Len returns the number of items in the permutation.
Len() int
// Less reports whether the item with index i
// is less than the item with index j.
//
// Less must describe a transitive ordering:
// - if both Less(i, j) and Less(j, k) are true, then Less(i, k) must be true as well.
// - if both Less(i, j) and Less(j, k) are false, then Less(i, k) must be false as well.
//
// Note that floating-point comparison
// (the < operator on float32 or float64 values)
// is not a transitive ordering when not-a-number (NaN) values are involved.
//
// It panics if i or j is out of range.
Less(i, j int) bool
// Swap exchanges the items with indexes i and j.
//
// It panics if i or j is out of range.
Swap(i, j int)
}
Interface represents an integer-indexed permutation with method Less.
Click to show internal directories.
Click to hide internal directories.