permutation

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2024 License: AGPL-3.0 Imports: 1 Imported by: 0

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

func NextPermutation(itf Interface) bool

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 strict weak ordering.
	// See <https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings>
	// for details.
	//
	// Note that floating-point comparison
	// (the < operator on float32 or float64 values)
	// is not a strict weak 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.

It is consistent with the interface sort.Interface.

Jump to

Keyboard shortcuts

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