permutation

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2020 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package permutation provides algorithms about permutations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NextPermutation

func NextPermutation(data Interface) bool

Transform data to its next permutation in lexical order. It returns false if data.Len() == 0 or the permutations are exhausted, and true otherwise. Time complexity: O(n), where n = data.Len().

Types

type ArrayAdapter

type ArrayAdapter struct {
	Data   sequence.Array
	LessFn function.LessFunc
}

An adapter for: Array + LessFunc -> Interface.

func (*ArrayAdapter) Len

func (ad *ArrayAdapter) Len() int

func (*ArrayAdapter) Less

func (ad *ArrayAdapter) Less(i, j int) bool

func (*ArrayAdapter) Swap

func (ad *ArrayAdapter) Swap(i, j int)

type Interface

type Interface interface {
	// Return the number of items in the permutation.
	// It returns 0 if the permutation is nil.
	Len() int

	// Test whether the i-th item is less than j-th item of the permutation.
	// It panics if i or j is out of range.
	Less(i, j int) bool

	// Swap the i-th and j-th items.
	// It panics if i or j is out of range.
	Swap(i, j int)
}

A type standing for an integer-indexed permutation. It is the same as sort.Interface.

Jump to

Keyboard shortcuts

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