/
githubmirror
/
photoprism
Обзор
Документация
Войти
/
githubmirror
/
photoprism
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
pkg/list/contains.go
54 строки
959 B
Michael Mayer
Go: Apply go fix modernizations across backend packages
20 фев 2026, 05:54
20 фев 2026, 05:54
a2b7615
Код
Авторство
О чём код?
package list import "slices" // Any matches everything. const Any = "*" // All is kept for backward compatibility, but deprecated. const All = Any // Contains tests if a string is contained in the list. func Contains(list []string, s string) bool { if len(list) == 0 || s == "" { return false } else if s == Any { return true } // Find matches. for i := range list { if s == list[i] || list[i] == Any { return true } } return false } // ContainsAny tests if two lists have at least one common entry. func ContainsAny(l, s []string) bool { if len(l) == 0 || len(s) == 0 { return false } if slices.Contains(s, Any) { return true } // Build a set from the smaller slice for O(n+m) intersection. a, b := l, s if len(a) > len(b) { a, b = b, a } set := make(map[string]struct{}, len(a)) for i := range a { set[a[i]] = struct{}{} } for j := range b { if _, ok := set[b[j]]; ok { return true } } return false }