@@ -3,7 +3,6 @@ package incrversion
3
3
import (
4
4
"context"
5
5
"reflect"
6
- "sort"
7
6
8
7
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/db_interface"
9
8
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
@@ -101,7 +100,7 @@ func (o *VersionSynchronizer[V, R]) Sync() error {
101
100
}
102
101
} else {
103
102
if len (delIDs ) > 0 {
104
- lvs .UIDList = DeleteElements (lvs .UIDList , delIDs )
103
+ lvs .UIDList = datautil . DeleteElems (lvs .UIDList , delIDs ... )
105
104
}
106
105
if len (insert ) > 0 {
107
106
lvs .UIDList = append (lvs .UIDList , datautil .Slice (insert , o .Key )... )
@@ -179,7 +178,7 @@ func (o *VersionSynchronizer[V, R]) CheckVersionSync() error {
179
178
}
180
179
if lvs .Version + 1 == version {
181
180
if len (delIDs ) > 0 {
182
- lvs .UIDList = DeleteElements (lvs .UIDList , delIDs )
181
+ lvs .UIDList = datautil . DeleteElems (lvs .UIDList , delIDs ... )
183
182
}
184
183
if len (insert ) > 0 {
185
184
lvs .UIDList = append (lvs .UIDList , datautil .Slice (insert , o .Key )... )
@@ -232,50 +231,3 @@ func (o *VersionSynchronizer[V, R]) CheckVersionSync() error {
232
231
return o .Sync ()
233
232
}
234
233
}
235
-
236
- // DeleteElements removes elements from a slice that are contained in another slice, while maintaining the order of the slice
237
- func DeleteElements [E comparable ](es []E , toDelete []E ) []E {
238
- // Store the elements to be deleted in a hash set
239
- deleteSet := make (map [E ]struct {}, len (toDelete ))
240
- for _ , e := range toDelete {
241
- deleteSet [e ] = struct {}{}
242
- }
243
-
244
- // Use an index j to track the new slice position
245
- j := 0
246
- for _ , e := range es {
247
- if _ , found := deleteSet [e ]; ! found {
248
- es [j ] = e
249
- j ++
250
- }
251
- }
252
- return es [:j ]
253
- }
254
-
255
- // DeleteElement removes a specified element from a slice while maintaining the order of the slice
256
- func DeleteElement [E comparable ](es []E , element E ) []E {
257
- j := 0
258
- for _ , e := range es {
259
- if e != element {
260
- es [j ] = e
261
- j ++
262
- }
263
- }
264
- return es [:j ]
265
- }
266
-
267
- // Slice converts slice types in batches and sorts the resulting slice using a custom comparator
268
- func Slice [E any , T any ](es []E , fn func (e E ) T , less func (a , b T ) bool ) []T {
269
- // Convert the slice
270
- v := make ([]T , len (es ))
271
- for i := 0 ; i < len (es ); i ++ {
272
- v [i ] = fn (es [i ])
273
- }
274
-
275
- // Sort the slice
276
- sort .Slice (v , func (i , j int ) bool {
277
- return less (v [i ], v [j ])
278
- })
279
-
280
- return v
281
- }
0 commit comments