summaryrefslogtreecommitdiffstats
path: root/modules/base
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2022-10-12 07:18:26 +0200
committerGitHub <noreply@github.com>2022-10-12 13:18:26 +0800
commit0e57ff7eee4ac71d923f970d15889ad4d50f97a9 (patch)
treee5a92c55af5366924bd40ae14b4bf12842239193 /modules/base
parente84558b0931309cf1f4f2767bc47296483b9b3e1 (diff)
downloadgitea-0e57ff7eee4ac71d923f970d15889ad4d50f97a9.tar.gz
gitea-0e57ff7eee4ac71d923f970d15889ad4d50f97a9.zip
Add generic set type (#21408)
This PR adds a generic set type to get rid of maps used as sets. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'modules/base')
-rw-r--r--modules/base/tool.go9
-rw-r--r--modules/base/tool_test.go9
2 files changed, 0 insertions, 18 deletions
diff --git a/modules/base/tool.go b/modules/base/tool.go
index a981fd6c57..f1e4a3bf97 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -241,15 +241,6 @@ func Int64sToStrings(ints []int64) []string {
return strs
}
-// Int64sToMap converts a slice of int64 to a int64 map.
-func Int64sToMap(ints []int64) map[int64]bool {
- m := make(map[int64]bool)
- for _, i := range ints {
- m[i] = true
- }
- return m
-}
-
// Int64sContains returns if a int64 in a slice of int64
func Int64sContains(intsSlice []int64, a int64) bool {
for _, c := range intsSlice {
diff --git a/modules/base/tool_test.go b/modules/base/tool_test.go
index 6685168bac..87de898e0b 100644
--- a/modules/base/tool_test.go
+++ b/modules/base/tool_test.go
@@ -214,16 +214,7 @@ func TestInt64sToStrings(t *testing.T) {
)
}
-func TestInt64sToMap(t *testing.T) {
- assert.Equal(t, map[int64]bool{}, Int64sToMap([]int64{}))
- assert.Equal(t,
- map[int64]bool{1: true, 4: true, 16: true},
- Int64sToMap([]int64{1, 4, 16}),
- )
-}
-
func TestInt64sContains(t *testing.T) {
- assert.Equal(t, map[int64]bool{}, Int64sToMap([]int64{}))
assert.True(t, Int64sContains([]int64{6, 44324, 4324, 32, 1, 2323}, 1))
assert.True(t, Int64sContains([]int64{2323}, 2323))
assert.False(t, Int64sContains([]int64{6, 44324, 4324, 32, 1, 2323}, 232))