MCPcopy Index your code
hub / github.com/cortexproject/cortex / GenerateTokens

Method GenerateTokens

pkg/ring/token_generator.go:38–66  ·  view source on GitHub ↗
(ring *Desc, _, _ string, numTokens int, _ bool)

Source from the content-addressed store, hash-verified

36}
37
38func (g *RandomTokenGenerator) GenerateTokens(ring *Desc, _, _ string, numTokens int, _ bool) []uint32 {
39 if numTokens <= 0 {
40 return []uint32{}
41 }
42
43 takenTokens := ring.GetTokens()
44 r := rand.New(rand.NewSource(time.Now().UnixNano()))
45
46 used := make(map[uint32]bool, len(takenTokens))
47 for _, v := range takenTokens {
48 used[v] = true
49 }
50
51 tokens := make([]uint32, 0, numTokens)
52 for i := 0; i < numTokens; {
53 candidate := r.Uint32()
54 if used[candidate] {
55 continue
56 }
57 used[candidate] = true
58 tokens = append(tokens, candidate)
59 i++
60 }
61
62 // Ensure returned tokens are sorted.
63 slices.Sort(tokens)
64
65 return tokens
66}
67
68type MinimizeSpreadTokenGenerator struct {
69 innerGenerator TokenGenerator

Calls 1

GetTokensMethod · 0.45