From 844e165a7d11258957a332a61d216ea1914aced3 Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Thu, 11 May 2023 14:39:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0ToMapBool=E8=BE=85=E5=8A=A9?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/hash/convert.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/utils/hash/convert.go b/utils/hash/convert.go index 8ffc967..a12a7e5 100644 --- a/utils/hash/convert.go +++ b/utils/hash/convert.go @@ -36,6 +36,15 @@ func ToMap[V any](slice []V) map[int]V { return m } +// ToMapBool 将切片转换为 map,value作为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 func ToSortMap[V any](slice []V) SortMap[int, V] { var m SortMap[int, V]