Skip to content

Commit

Permalink
Create util.go
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkRosemaker committed Nov 20, 2024
1 parent c1c14b2 commit efa4253
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package openapi

func setToMap[M ~map[K]V, K comparable, V any](
m *M, key K, v V,
getIndex func(V) int,
setIndex func(V, int),
) {
if *m == nil {
setIndex(v, 1)
*m = M{key: v}
return
}

highestIdx := 0
for _, v := range *m {
if idx := getIndex(v); idx > highestIdx {
highestIdx = idx
}
}

setIndex(v, highestIdx+1)
(*m)[key] = v
}

0 comments on commit efa4253

Please sign in to comment.