2022-08-15 15:55:27 +02:00
|
|
|
package main
|
|
|
|
|
2022-08-18 14:25:37 +02:00
|
|
|
import (
|
2022-08-25 18:13:29 +02:00
|
|
|
"sort"
|
2022-08-18 14:25:37 +02:00
|
|
|
|
2022-08-25 18:13:29 +02:00
|
|
|
"git.milar.in/milarin/tprint"
|
2023-01-13 13:38:51 +01:00
|
|
|
"git.milar.in/nyaanime/model"
|
2022-08-18 14:25:37 +02:00
|
|
|
)
|
|
|
|
|
2022-08-25 18:13:29 +02:00
|
|
|
func Map2Table[K comparable](title string, m map[K]int) string {
|
|
|
|
table := tprint.NewTable(title, "priority")
|
2022-08-21 21:14:44 +02:00
|
|
|
|
2023-01-13 13:38:51 +01:00
|
|
|
entries := make([]model.Pair[K, int], 0, len(m))
|
2022-08-25 18:13:29 +02:00
|
|
|
for name, priority := range m {
|
2023-01-13 13:38:51 +01:00
|
|
|
entries = append(entries, model.Pair[K, int]{First: name, Second: priority})
|
2022-08-21 21:14:44 +02:00
|
|
|
}
|
2022-08-25 18:13:29 +02:00
|
|
|
sort.Slice(entries, func(i, j int) bool { return entries[i].Second > entries[j].Second })
|
2022-08-21 21:14:44 +02:00
|
|
|
|
2022-08-25 18:13:29 +02:00
|
|
|
for _, entry := range entries {
|
|
|
|
table.AddRow(entry.First, entry.Second)
|
2022-08-22 14:14:14 +02:00
|
|
|
}
|
|
|
|
|
2022-08-25 18:13:29 +02:00
|
|
|
return table.String()
|
2022-08-22 14:14:14 +02:00
|
|
|
}
|