mirror of
https://github.com/hanzo-git/runner.git
synced 2026-10-30 19:33:27 +00:00
Native runner: module github.com/hanzo-git/runner, wire proto github.com/hanzo-git/actions-proto-go, command git-runner, GIT_* env, git expr context, git_* task-context keys, ghcr.io/hanzoai/runner-ubuntu job images. Derived work — upstream attribution + MIT terms in NOTICE/LICENSE. Co-authored-by: Hanzo Dev <[email protected]>
61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
// Copyright 2026 The Git Authors. All rights reserved.
|
|
// Copyright 2020 The nektos/act Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package common
|
|
|
|
import "slices"
|
|
|
|
// CartesianProduct takes map of lists and returns list of unique tuples
|
|
func CartesianProduct(mapOfLists map[string][]any) []map[string]any {
|
|
listNames := make([]string, 0)
|
|
lists := make([][]any, 0)
|
|
for k, v := range mapOfLists {
|
|
listNames = append(listNames, k)
|
|
lists = append(lists, v)
|
|
}
|
|
|
|
listCart := cartN(lists...)
|
|
|
|
rtn := make([]map[string]any, 0)
|
|
for _, list := range listCart {
|
|
vMap := make(map[string]any)
|
|
for i, v := range list {
|
|
vMap[listNames[i]] = v
|
|
}
|
|
rtn = append(rtn, vMap)
|
|
}
|
|
return rtn
|
|
}
|
|
|
|
func cartN(a ...[]any) [][]any {
|
|
c := 1
|
|
for _, a := range a {
|
|
c *= len(a)
|
|
}
|
|
if c == 0 || len(a) == 0 {
|
|
return nil
|
|
}
|
|
p := make([][]any, c)
|
|
b := make([]any, c*len(a))
|
|
n := make([]int, len(a))
|
|
s := 0
|
|
for i := range p {
|
|
e := s + len(a)
|
|
pi := b[s:e]
|
|
p[i] = pi
|
|
s = e
|
|
for j, n := range n {
|
|
pi[j] = a[j][n]
|
|
}
|
|
for j := range slices.Backward(n) {
|
|
n[j]++
|
|
if n[j] < len(a[j]) {
|
|
break
|
|
}
|
|
n[j] = 0
|
|
}
|
|
}
|
|
return p
|
|
}
|