添加ToMapBool辅助函数

This commit is contained in:
kercylan98 2023-05-11 14:39:51 +08:00
parent 0e2e36fde1
commit 844e165a7d
1 changed files with 9 additions and 0 deletions

View File

@ -36,6 +36,15 @@ func ToMap[V any](slice []V) map[int]V {
return m return m
} }
// ToMapBool 将切片转换为 mapvalue作为Key
func ToMapBool[V comparable](slice []V) map[V]bool {
var m = make(map[V]bool)
for _, v := range slice {
m[v] = true
}
return m
}
// ToSortMap 将切片转换为 SortMap // ToSortMap 将切片转换为 SortMap
func ToSortMap[V any](slice []V) SortMap[int, V] { func ToSortMap[V any](slice []V) SortMap[int, V] {
var m SortMap[int, V] var m SortMap[int, V]