mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
utils
This commit is contained in:
parent
a1e66e9da0
commit
f9e09d67bb
@ -547,7 +547,7 @@ func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsI
|
||||
return e.GroupID
|
||||
})
|
||||
resp.GroupInfos = utils.Slice(groups, func(e *relationTb.GroupModel) *sdkws.GroupInfo {
|
||||
return DbToPbGroupInfo(e, ownerMap[e.GroupID].UserID, uint32(groupMemberNumMap[e.GroupID]))
|
||||
return DbToPbGroupInfo(e, ownerMap[e.GroupID].UserID, groupMemberNumMap[e.GroupID])
|
||||
})
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -27,6 +27,11 @@ func SliceSub[E comparable](a, b []E) []E {
|
||||
return rs
|
||||
}
|
||||
|
||||
// SliceSubAny a中存在,b中不存在 (a-b)
|
||||
func SliceSubAny[E comparable, T any](a []E, b []T, fn func(t T) E) []E {
|
||||
return SliceSub(a, Slice(b, fn))
|
||||
}
|
||||
|
||||
// DistinctAny 去重
|
||||
func DistinctAny[E any, K comparable](es []E, fn func(e E) K) []E {
|
||||
v := make([]E, 0, len(es))
|
||||
@ -380,28 +385,6 @@ func Single[E comparable](a, b []E) []E {
|
||||
return v
|
||||
}
|
||||
|
||||
// SliceSub a中存在,b中不存在 (a-b)
|
||||
func SliceSub[E comparable](a, b []E) []E {
|
||||
k := make(map[E]struct{})
|
||||
for i := 0; i < len(b); i++ {
|
||||
k[b[i]] = struct{}{}
|
||||
}
|
||||
t := make(map[E]struct{})
|
||||
rs := make([]E, 0, len(a))
|
||||
for i := 0; i < len(a); i++ {
|
||||
e := a[i]
|
||||
if _, ok := t[e]; ok {
|
||||
continue
|
||||
}
|
||||
if _, ok := k[e]; ok {
|
||||
continue
|
||||
}
|
||||
rs = append(rs, e)
|
||||
t[e] = struct{}{}
|
||||
}
|
||||
return rs
|
||||
}
|
||||
|
||||
// Order 将ts按es排序
|
||||
func Order[E comparable, T any](es []E, ts []T, fn func(t T) E) []T {
|
||||
if len(es) == 0 || len(ts) == 0 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user