permute

package module
v0.24.2 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: MIT Imports: 1 Imported by: 0

README

permute GoDoc Go Report Card

Combination sequence iterator. Requires GOEXPERIMENT=rangefunc.

This was made by translating https://docs.python.org/3/library/itertools.html#itertools.combinations from Python into Go.

Documentation

Overview

Package permute provides a combination sequence iterator. Requires GOEXPERIMENT=rangefunc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CombinationIndices added in v0.24.2

func CombinationIndices(n, k int) iter.Seq[[]int]

CombinationIndices returns an iterator of indices over the length K combinations of an N sized set in lexicograph order. The yielded slice is reused and must be cloned if kept.

E.g. for N = 3 and K = 2, it sets the yielded slice to {0, 1}, then {0, 2}, and finally {1, 2}.

func Combinations

func Combinations[E any, S ~[]E](s S, k int) iter.Seq[S]

Combinations takes a slice and returns an iterator over combinations of sub-slice combinations of length K. The yielded slice is reused and must be cloned if kept.

E.g. For []byte("abc"), 2; the yielded slice is set to "ab", "ac", and "bc" succesively.

func StringCombinations added in v0.24.2

func StringCombinations(s string, k int) iter.Seq[[]byte]

StringCombinations takes a string and returns an iterator over combinations of sub-string combinations of length K. The yielded byte slice is reused and must be cloned or turned into a string if kept.

E.g. For "abc", 2; the yielded slice is set to "ab", "ac", and "bc" succesively.

Types

This section is empty.

Jump to

Keyboard shortcuts

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