permute

package module
v2.0.0-beta2 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2022 License: MIT Imports: 0 Imported by: 1

README

permute

Go Reference

Permute is a Go package for generating permutations.

Documentation

Overview

Package permute implements a generic method for in-place generation of all permutations for ordered collections.

Example (Ints)
s := []int{5, 7}
p := permute.Slice(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.

func New

func New(v Interface) *Permuter

New gives a Permuter to generate all permutations of the elements of v.

func Slice

func Slice[S ~[]T, T any](s S) *Permuter

Slice constructs a Permuter for a slice.

func (*Permuter) Permute

func (p *Permuter) Permute() bool

Permute generates the next permutation of the contained collection in-place. If it returns false, the iteration is finished.

Jump to

Keyboard shortcuts

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