1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-07 14:12:28 +08:00

refactor: change slice Contain logic, convert to map first, then check existence

This commit is contained in:
dudaodong
2022-07-22 10:22:34 +08:00
parent b5ba9ba573
commit 105ab49763

View File

@@ -14,13 +14,13 @@ import (
// Contain check if the value is in the slice or not
func Contain[T comparable](slice []T, value T) bool {
set := make(map[T]struct{}, len(slice))
for _, v := range slice {
if v == value {
return true
}
set[v] = struct{}{}
}
return false
_, ok := set[value]
return ok
}
// ContainSubSlice check if the slice contain subslice or not