mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
1
This commit is contained in:
parent
4d4a451926
commit
f98d894a4b
@ -89,6 +89,26 @@ func Contain[E comparable](es []E, e E) bool {
|
||||
return IndexOf(es, e) >= 0
|
||||
}
|
||||
|
||||
// DuplicateAny judge whether it is repeated
|
||||
func DuplicateAny[E any, K comparable](es []E, fn func(e E) K) bool {
|
||||
t := make(map[K]struct{})
|
||||
for _, e := range es {
|
||||
k := fn(e)
|
||||
if _, ok := t[k]; ok {
|
||||
return true
|
||||
}
|
||||
t[k] = struct{}{}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Duplicate judge whether it is repeated
|
||||
func Duplicate[E comparable](es []E) bool {
|
||||
return DuplicateAny(es, func(e E) E {
|
||||
return e
|
||||
})
|
||||
}
|
||||
|
||||
// SliceToMapOkAny slice to map
|
||||
func SliceToMapOkAny[E any, K comparable, V any](es []E, fn func(e E) (K, V, bool)) map[K]V {
|
||||
kv := make(map[K]V)
|
||||
|
Loading…
x
Reference in New Issue
Block a user