Skip to content

Commit

Permalink
Add common.ReverseMap
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Nov 12, 2024
1 parent 57af72d commit 703d4ff
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions common/cond.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ func Reverse[T any](arr []T) []T {
return arr
}

func ReverseMap[K comparable, V comparable](m map[K]V) map[V]K {
ret := make(map[V]K, len(m))
for k, v := range m {
ret[v] = k
}
return ret
}

func Done(ctx context.Context) bool {
select {
case <-ctx.Done():
Expand Down

0 comments on commit 703d4ff

Please sign in to comment.