2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 18:39:22 +00:00
|
|
|
|
2024-01-10 16:19:20 +00:00
|
|
|
package structs
|
2020-08-17 21:24:49 +00:00
|
|
|
|
2024-01-10 16:19:20 +00:00
|
|
|
import "math/rand"
|
2021-07-19 22:22:51 +00:00
|
|
|
|
|
|
|
type RecursorStrategy string
|
|
|
|
|
|
|
|
const (
|
|
|
|
RecursorStrategySequential RecursorStrategy = "sequential"
|
|
|
|
RecursorStrategyRandom RecursorStrategy = "random"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s RecursorStrategy) Indexes(max int) []int {
|
|
|
|
switch s {
|
|
|
|
case RecursorStrategyRandom:
|
|
|
|
return rand.Perm(max)
|
|
|
|
default:
|
|
|
|
idxs := make([]int, max)
|
|
|
|
for i := range idxs {
|
|
|
|
idxs[i] = i
|
|
|
|
}
|
|
|
|
return idxs
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|